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;
|
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
|
||||||
|
{
|
||||||
|
newReceiveCancellationTokenSource = new CancellationTokenSource();
|
||||||
|
newClient = new UdpClient();
|
||||||
|
newClient.Client.ReceiveBufferSize = bufferSize;
|
||||||
|
newClient.Client.SendBufferSize = bufferSize;
|
||||||
|
newClient.Connect(hostname, port);
|
||||||
|
|
||||||
|
lock (stateLock)
|
||||||
{
|
{
|
||||||
receiveCancellationTokenSource = new CancellationTokenSource();
|
if (!connectEnabled || client != null)
|
||||||
client = new UdpClient();
|
{
|
||||||
client.Client.ReceiveBufferSize = BufferSize;
|
newClient.Close();
|
||||||
client.Client.SendBufferSize = BufferSize;
|
newReceiveCancellationTokenSource.Cancel();
|
||||||
client.Connect(Hostname, Port);
|
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;
|
||||||
}
|
}
|
||||||
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);
|
newReceiveCancellationTokenSource.Cancel();
|
||||||
CleanupClient();
|
newReceiveCancellationTokenSource.Dispose();
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
}
|
||||||
StartReconnectTimer();
|
|
||||||
|
lock (stateLock)
|
||||||
|
{
|
||||||
|
if (connectEnabled && client == null)
|
||||||
|
{
|
||||||
|
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
||||||
|
StartReconnectTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue