fix: Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Jonathan Arndt 2026-05-15 13:01:08 -07:00 committed by GitHub
parent c9f5af184b
commit b83af26b77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -225,33 +225,74 @@ namespace PepperDash.Core
return;
}
var hostname = Hostname;
var port = Port;
var bufferSize = BufferSize;
UdpClient newClient = null;
CancellationTokenSource newReceiveCancellationTokenSource = null;
CancellationToken startReceiveToken = default(CancellationToken);
var shouldStartReceive = false;
lock (stateLock)
{
connectEnabled = true;
if (client != null)
return;
}
try
{
receiveCancellationTokenSource = new CancellationTokenSource();
client = new UdpClient();
client.Client.ReceiveBufferSize = BufferSize;
client.Client.SendBufferSize = BufferSize;
client.Connect(Hostname, Port);
newReceiveCancellationTokenSource = new CancellationTokenSource();
newClient = new UdpClient();
newClient.Client.ReceiveBufferSize = bufferSize;
newClient.Client.SendBufferSize = bufferSize;
newClient.Connect(hostname, port);
lock (stateLock)
{
if (!connectEnabled || client != null)
{
newClient.Close();
newReceiveCancellationTokenSource.Cancel();
newReceiveCancellationTokenSource.Dispose();
return;
}
receiveCancellationTokenSource = newReceiveCancellationTokenSource;
client = newClient;
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
StartReceive(receiveCancellationTokenSource.Token);
startReceiveToken = receiveCancellationTokenSource.Token;
shouldStartReceive = true;
}
if (shouldStartReceive)
StartReceive(startReceiveToken);
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error connecting UDP client {0}", this, Key);
CleanupClient();
if (newClient != null)
newClient.Close();
if (newReceiveCancellationTokenSource != null)
{
newReceiveCancellationTokenSource.Cancel();
newReceiveCancellationTokenSource.Dispose();
}
lock (stateLock)
{
if (connectEnabled && client == null)
{
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
StartReconnectTimer();
}
}
}
}
/// <summary>
/// Disconnect method