mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-07-02 10:38:16 +00:00
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:
parent
c9f5af184b
commit
b83af26b77
1 changed files with 53 additions and 12 deletions
|
|
@ -225,30 +225,71 @@ 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
|
||||
try
|
||||
{
|
||||
newReceiveCancellationTokenSource = new CancellationTokenSource();
|
||||
newClient = new UdpClient();
|
||||
newClient.Client.ReceiveBufferSize = bufferSize;
|
||||
newClient.Client.SendBufferSize = bufferSize;
|
||||
newClient.Connect(hostname, port);
|
||||
|
||||
lock (stateLock)
|
||||
{
|
||||
receiveCancellationTokenSource = new CancellationTokenSource();
|
||||
client = new UdpClient();
|
||||
client.Client.ReceiveBufferSize = BufferSize;
|
||||
client.Client.SendBufferSize = BufferSize;
|
||||
client.Connect(Hostname, Port);
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
if (shouldStartReceive)
|
||||
StartReceive(startReceiveToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogMessage(ex, "Error connecting UDP client {0}", this, Key);
|
||||
|
||||
if (newClient != null)
|
||||
newClient.Close();
|
||||
|
||||
if (newReceiveCancellationTokenSource != null)
|
||||
{
|
||||
Debug.LogMessage(ex, "Error connecting UDP client {0}", this, Key);
|
||||
CleanupClient();
|
||||
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
||||
StartReconnectTimer();
|
||||
newReceiveCancellationTokenSource.Cancel();
|
||||
newReceiveCancellationTokenSource.Dispose();
|
||||
}
|
||||
|
||||
lock (stateLock)
|
||||
{
|
||||
if (connectEnabled && client == null)
|
||||
{
|
||||
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
||||
StartReconnectTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue