Revert "Feature/ssh dispose"

This commit is contained in:
Andrew Welker
2022-12-12 09:33:13 -07:00
parent ae5b1684c8
commit 2abf5749de

View File

@@ -312,17 +312,15 @@ namespace PepperDash.Core
/// </summary> /// </summary>
public void Disconnect() public void Disconnect()
{ {
try ConnectEnabled = false;
{
connectLock.Enter();
// Stop trying reconnects, if we are // Stop trying reconnects, if we are
ReconnectTimer.Stop(); if (ReconnectTimer != null)
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
}
finally
{ {
connectLock.Leave(); ReconnectTimer.Stop();
ReconnectTimer = null;
} }
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
} }
/// <summary> /// <summary>
@@ -334,17 +332,38 @@ namespace PepperDash.Core
if (Client != null) if (Client != null)
{ {
try IsConnecting = false;
{
Client.Disconnect(); Client.Disconnect();
Client.Dispose();
Client = null; Client = null;
ClientStatus = status; ClientStatus = status;
Debug.Console(1, this, "Disconnected client"); Debug.Console(1, this, "Disconnected");
} }
catch (Exception ex) }
/// <summary>
/// Anything to do with reestablishing connection on failures
/// </summary>
void HandleConnectionFailure()
{ {
Debug.Console(1, this, "Exception killing client: {0}", ex.Message); KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
Debug.Console(1, this, "Client nulled due to connection failure. AutoReconnect: {0}, ConnectEnabled: {1}", AutoReconnect, ConnectEnabled);
if (AutoReconnect && ConnectEnabled)
{
Debug.Console(1, this, "Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
if (ReconnectTimer == null)
{
ReconnectTimer = new CTimer(o =>
{
Connect();
}, AutoReconnectIntervalMs);
Debug.Console(1, this, "Attempting connection in {0} seconds",
(float) (AutoReconnectIntervalMs/1000));
}
else
{
Debug.Console(1, this, "{0} second reconnect cycle running",
(float) (AutoReconnectIntervalMs/1000));
} }
} }
} }