From cca71cb6729039cc805e8f657ca093134e70ef9e Mon Sep 17 00:00:00 2001 From: Kenneth_aa_cp Date: Tue, 11 Sep 2012 12:10:03 +0000 Subject: [PATCH] Added a comment regarding exception thrown when local socket is dead, as it shows up as first-chance exception in the output window. --- Renci.SshClient/Renci.SshNet/Session.NET.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Renci.SshClient/Renci.SshNet/Session.NET.cs b/Renci.SshClient/Renci.SshNet/Session.NET.cs index 076e900f..71e08712 100644 --- a/Renci.SshClient/Renci.SshNet/Session.NET.cs +++ b/Renci.SshClient/Renci.SshNet/Session.NET.cs @@ -80,6 +80,13 @@ namespace Renci.SshNet response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray()); } + /// + /// Function to read amount of data before returning, or throwing an exception. + /// + /// The amount wanted. + /// The buffer to read to. + /// Happens when the socket is closed. + /// Unhandled exception. partial void SocketRead(int length, ref byte[] buffer) { var offset = 0; @@ -97,7 +104,17 @@ namespace Renci.SshNet } else { - throw new SshConnectionException("An established connection was aborted by the software in your host machine.", DisconnectReason.ConnectionLost); + // 2012-09-11: Kenneth_aa + // When Disconnect or Dispose is called, this throws SshConnectionException(), which... + // 1 - goes up to ReceiveMessage() + // 2 - up again to MessageListener() + // which is where there is a catch-all exception block so it can notify event listeners. + // 3 - MessageListener then again calls RaiseError(). + // There the exception is checked for the exception thrown here (ConnectionLost), and if it matches it will not call Session.SendDisconnect(). + // + // Adding a check for this._isDisconnecting causes ReceiveMessage() to throw SshConnectionException: "Bad packet length {0}". + // + throw new SshConnectionException("An established connection was aborted by the software in your host machine.", DisconnectReason.ConnectionLost); } } catch (SocketException exp)