Skip to content

Commit

Permalink
Merge pull request #237 from peppy/fix-reconnect-overhead
Browse files Browse the repository at this point in the history
Reduce overhead in `ManagedNamedPipeClient` during connection loop
  • Loading branch information
Lachee authored Jul 16, 2023
2 parents db3667e + 2ec401e commit 83bcc9e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions DiscordRPC/IO/ManagedNamedPipeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ private bool AttemptConnection(int pipe, bool isSandbox = false)
{
Logger.Info("Attempting to connect to '{0}'", pipename);
_stream = new NamedPipeClientStream(".", pipename, PipeDirection.InOut, PipeOptions.Asynchronous);
_stream.Connect(1000);

// Intentionally use a timeout of 0 here to avoid spinlock overhead.
// We are already performing local retry logic, so this is not required.
_stream.Connect(0);

//Spin for a bit while we wait for it to finish connecting
Logger.Trace("Waiting for connection...");
Expand Down Expand Up @@ -378,7 +381,7 @@ public void Close()
return;
}

//flush and dispose
//flush and dispose
try
{
//Wait for the stream object to become available.
Expand Down

0 comments on commit 83bcc9e

Please sign in to comment.