|  | @@ -80,6 +80,13 @@ namespace Renci.SshNet
 | 
											
												
													
														|  |                  response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
 |  |                  response = encoding.GetString(buffer.Take(buffer.Count - 1).ToArray());
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +        /// <summary>
 | 
											
												
													
														|  | 
 |  | +        /// Function to read <paramref name="length"/> amount of data before returning, or throwing an exception.
 | 
											
												
													
														|  | 
 |  | +        /// </summary>
 | 
											
												
													
														|  | 
 |  | +        /// <param name="length">The amount wanted.</param>
 | 
											
												
													
														|  | 
 |  | +        /// <param name="buffer">The buffer to read to.</param>
 | 
											
												
													
														|  | 
 |  | +        /// <exception cref="SshConnectionException">Happens when the socket is closed.</exception>
 | 
											
												
													
														|  | 
 |  | +        /// <exception cref="Exception">Unhandled exception.</exception>
 | 
											
												
													
														|  |          partial void SocketRead(int length, ref byte[] buffer)
 |  |          partial void SocketRead(int length, ref byte[] buffer)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  |              var offset = 0;
 |  |              var offset = 0;
 | 
											
										
											
												
													
														|  | @@ -97,7 +104,17 @@ namespace Renci.SshNet
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
												
													
														|  |                      else
 |  |                      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)
 |  |                  catch (SocketException exp)
 |