fix: additional logging and kill client on IO exception

This commit is contained in:
jtalborough
2025-02-10 14:35:22 -05:00
parent 44fb41b42e
commit 3df50e117a

View File

@@ -496,40 +496,49 @@ namespace PepperDash.Core
/// <param name="text"></param> /// <param name="text"></param>
public void SendText(string text) public void SendText(string text)
{ {
try try
{ {
if (Client != null && TheStream != null && IsConnected) if (Client != null && TheStream != null && IsConnected)
{ {
if (StreamDebugging.TxStreamDebuggingIsEnabled) if (StreamDebugging.TxStreamDebuggingIsEnabled)
Debug.Console(0, Debug.Console(0,
this, this,
"Sending {0} characters of text: '{1}'", "Sending {0} characters of text: '{1}'",
text.Length, text.Length,
ComTextHelper.GetDebugText(text)); ComTextHelper.GetDebugText(text));
TheStream.Write(text); TheStream.Write(text);
TheStream.Flush(); TheStream.Flush();
} }
else else
{ {
Debug.Console(1, this, "Client is null or disconnected. Cannot Send Text"); Debug.Console(1, this, "Client is null or disconnected. Cannot Send Text");
} }
} }
catch (ObjectDisposedException ex) catch (ObjectDisposedException ex)
{ {
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Exception: {0}", ex.Message); Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Exception: {0}", ex.Message);
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Stack Trace: {0}", ex.StackTrace); Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Stack Trace: {0}", ex.StackTrace);
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED); KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
ReconnectTimer.Reset();
}
catch (Crestron.SimplSharp.CrestronIO.IOException ex)
{
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Crestron.SimplSharp.CrestronIO.IOException: {0} -\n{1}\n", ex.Message, ex);
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Crestron.SimplSharp.CrestronIO.IOException Stack Trace: {0}", ex.StackTrace);
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Crestron.SimplSharp.CrestronIO.IOException Stream write failed");
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
ReconnectTimer.Reset(); ReconnectTimer.Reset();
}
catch (Exception ex)
{
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Exception: {0}", ex.Message);
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Stack Trace: {0}", ex.StackTrace);
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Stream write failed"); }
} catch (Exception ex)
{
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Exception: {0} -\n{1}\n", ex.Message, ex);
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.StackTrace);
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Stream write failed");
}
} }
/// <summary> /// <summary>