Parcourir la source

Fix IsConnected property behaviour
Fix SocketReadLine if 0 bytes received

olegkap_cp il y a 13 ans
Parent
commit
908321c502

+ 5 - 1
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]);
             }

+ 3 - 3
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; }
         }
     }
-}
+}