From 908321c5027008dce1c1fe18f230099342a9112e Mon Sep 17 00:00:00 2001 From: olegkap_cp Date: Wed, 6 Jun 2012 13:11:00 +0000 Subject: [PATCH] Fix IsConnected property behaviour Fix SocketReadLine if 0 bytes received --- Renci.SshClient/Renci.SshNet/Session.NET.cs | 6 +++++- Renci.SshClient/Renci.SshNet/Session.cs | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Renci.SshClient/Renci.SshNet/Session.NET.cs b/Renci.SshClient/Renci.SshNet/Session.NET.cs index 5dd519e5..b61ffefa 100644 --- a/Renci.SshClient/Renci.SshNet/Session.NET.cs +++ b/Renci.SshClient/Renci.SshNet/Session.NET.cs @@ -59,7 +59,11 @@ namespace Renci.SshNet var data = new byte[1]; do { - this._socket.Receive(data); + var received = this._socket.Receive(data); + + // If zero bytes received then exit + if (received == 0) + break; buffer.Add(data[0]); } diff --git a/Renci.SshClient/Renci.SshNet/Session.cs b/Renci.SshClient/Renci.SshNet/Session.cs index a46ba4ff..42aaf9d9 100644 --- a/Renci.SshClient/Renci.SshNet/Session.cs +++ b/Renci.SshClient/Renci.SshNet/Session.cs @@ -183,7 +183,7 @@ namespace Renci.SshNet { get { - return this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null; + return (!this._isDisconnecting && this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null) && !(this._socket.Poll(10, SelectMode.SelectRead)); } } @@ -1844,7 +1844,7 @@ namespace Renci.SshNet var encoding = new Renci.SshNet.Common.ASCIIEncoding(); this.SocketWrite(encoding.GetBytes(string.Format("CONNECT {0}:{1} HTTP/1.0\r\n", this.ConnectionInfo.Host, this.ConnectionInfo.Port))); - + // Sent proxy authorization is specified if (!string.IsNullOrEmpty(this.ConnectionInfo.ProxyUsername)) { @@ -2047,4 +2047,4 @@ namespace Renci.SshNet public Type Type { get; set; } } } -} +} \ No newline at end of file