mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-15 20:54:46 +00:00
Changes lock to CCriticalSection
This commit is contained in:
@@ -129,7 +129,7 @@ namespace PepperDash.Core
|
||||
CTimer ReconnectTimer;
|
||||
|
||||
//Lock object to prevent simulatneous connect/disconnect operations
|
||||
private readonly object connectLock = new object();
|
||||
private CCriticalSection connectLock = new CCriticalSection();
|
||||
|
||||
private bool DisconnectLogged = false;
|
||||
|
||||
@@ -163,7 +163,6 @@ namespace PepperDash.Core
|
||||
public GenericSshClient()
|
||||
: base(SPlusKey)
|
||||
{
|
||||
StreamDebugging = new CommunicationStreamDebugging(SPlusKey);
|
||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||
AutoReconnectIntervalMs = 5000;
|
||||
|
||||
@@ -213,8 +212,10 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
ConnectEnabled = true;
|
||||
lock (connectLock)
|
||||
|
||||
try
|
||||
{
|
||||
connectLock.Enter();
|
||||
if (IsConnected)
|
||||
{
|
||||
Debug.Console(1, this, "Connection already connected. Exiting Connect()");
|
||||
@@ -296,6 +297,10 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
connectLock.Leave();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -303,11 +308,16 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
lock(connectLock)
|
||||
try
|
||||
{
|
||||
connectLock.Enter();
|
||||
// Stop trying reconnects, if we are
|
||||
ReconnectTimer.Stop();
|
||||
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
|
||||
}
|
||||
finally
|
||||
{
|
||||
connectLock.Leave();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,10 +414,15 @@ namespace PepperDash.Core
|
||||
else
|
||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Unhandled SSH client error: {0}", e.Exception);
|
||||
|
||||
lock (connectLock)
|
||||
try
|
||||
{
|
||||
connectLock.Enter();
|
||||
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY);
|
||||
}
|
||||
finally
|
||||
{
|
||||
connectLock.Leave();
|
||||
}
|
||||
if (AutoReconnect && ConnectEnabled)
|
||||
{
|
||||
Debug.Console(1, this, "Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||
|
||||
Reference in New Issue
Block a user