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)