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; 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) lock (stateLock)
{ {
connectEnabled = true; connectEnabled = true;
if (client != null) if (client != null)
return; return;
}
try try
{ {
receiveCancellationTokenSource = new CancellationTokenSource(); newReceiveCancellationTokenSource = new CancellationTokenSource();
client = new UdpClient(); newClient = new UdpClient();
client.Client.ReceiveBufferSize = BufferSize; newClient.Client.ReceiveBufferSize = bufferSize;
client.Client.SendBufferSize = BufferSize; newClient.Client.SendBufferSize = bufferSize;
client.Connect(Hostname, Port); 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; ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite); reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
StartReceive(receiveCancellationTokenSource.Token); startReceiveToken = receiveCancellationTokenSource.Token;
shouldStartReceive = true;
}
if (shouldStartReceive)
StartReceive(startReceiveToken);
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogMessage(ex, "Error connecting UDP client {0}", this, Key); 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; ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
StartReconnectTimer(); StartReconnectTimer();
} }
} }
} }
}
/// <summary> /// <summary>
/// Disconnect method /// Disconnect method