mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-15 12:44:48 +00:00
Merge pull request #12 from PepperDash/hotfix/sshClient-connect-protection
Adds semaphore to GenericSshClient.Connect()
This commit is contained in:
@@ -62,6 +62,8 @@ namespace PepperDash.Core
|
|||||||
get { return ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
get { return ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsConnecting = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// S+ helper for IsConnected
|
/// S+ helper for IsConnected
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -184,6 +186,13 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
|
if (IsConnecting)
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Connection attempt in progress. Exiting Connect()");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IsConnecting = true;
|
||||||
ConnectEnabled = true;
|
ConnectEnabled = true;
|
||||||
Debug.Console(1, this, "attempting connect");
|
Debug.Console(1, this, "attempting connect");
|
||||||
|
|
||||||
@@ -236,6 +245,7 @@ namespace PepperDash.Core
|
|||||||
//TheStream.ErrorOccurred += TheStream_ErrorOccurred;
|
//TheStream.ErrorOccurred += TheStream_ErrorOccurred;
|
||||||
Debug.Console(1, this, "Connected");
|
Debug.Console(1, this, "Connected");
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
|
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
|
||||||
|
IsConnecting = false;
|
||||||
return; // Success will not pass here
|
return; // Success will not pass here
|
||||||
}
|
}
|
||||||
catch (SshConnectionException e)
|
catch (SshConnectionException e)
|
||||||
@@ -291,6 +301,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (Client != null)
|
if (Client != null)
|
||||||
{
|
{
|
||||||
|
IsConnecting = false;
|
||||||
Client.Disconnect();
|
Client.Disconnect();
|
||||||
Client = null;
|
Client = null;
|
||||||
ClientStatus = status;
|
ClientStatus = status;
|
||||||
@@ -303,6 +314,7 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void HandleConnectionFailure()
|
void HandleConnectionFailure()
|
||||||
{
|
{
|
||||||
|
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
|
|
||||||
Debug.Console(2, this, "Client nulled due to connection failure. AutoReconnect: {0}, ConnectEnabled: {1}", AutoReconnect, ConnectEnabled);
|
Debug.Console(2, this, "Client nulled due to connection failure. AutoReconnect: {0}, ConnectEnabled: {1}", AutoReconnect, ConnectEnabled);
|
||||||
|
|||||||
Reference in New Issue
Block a user