Просмотр исходного кода

Ensure Queue.Dequeue operation is called only when data still availalbe in queue

olegkap_cp 12 лет назад
Родитель
Сommit
8e64b8f21b

+ 1 - 1
Renci.SshClient/Renci.SshNet/Common/PipeStream.cs

@@ -181,7 +181,7 @@
                     Monitor.Wait(this._buffer);
 
                 // fill the read buffer
-                for (; readLength < count && Length > 0; readLength++)
+                for (; readLength < count && Length > 0 && this._buffer.Count > 0; readLength++)
                 {
                     buffer[readLength] = this._buffer.Dequeue();
                 }

+ 5 - 4
Renci.SshClient/Renci.SshNet/ShellStream.cs

@@ -279,7 +279,7 @@ namespace Renci.SshNet
                             {
                                 var result = text.Substring(0, match.Index + match.Length);
 
-                                for (int i = 0; i < match.Index + match.Length; i++)
+                                for (int i = 0; i < match.Index + match.Length && this._incoming.Count > 0; i++)
                                 {
                                     //  Remove processed items from the queue
                                     this._incoming.Dequeue();
@@ -392,7 +392,7 @@ namespace Renci.SshNet
                                 {
                                     var result = text.Substring(0, match.Index + match.Length);
 
-                                    for (int i = 0; i < match.Index + match.Length; i++)
+                                    for (int i = 0; i < match.Index + match.Length && this._incoming.Count > 0; i++)
                                     {
                                         //  Remove processed items from the queue
                                         this._incoming.Dequeue();
@@ -410,6 +410,7 @@ namespace Renci.SshNet
                             }
                         }
                     }
+
                     if (timeout != null)
                     {
                         if (!this._dataReceived.WaitOne(timeout))
@@ -511,7 +512,7 @@ namespace Renci.SshNet
                     if (match.Success)
                     {
                         //  Remove processed items from the queue
-                        for (int i = 0; i < match.Index + match.Length; i++)
+                        for (int i = 0; i < match.Index + match.Length && this._incoming.Count > 0; i++)
                         {
                             this._incoming.Dequeue();
                         }
@@ -570,7 +571,7 @@ namespace Renci.SshNet
                         text = text.Substring(0, index);
 
                         //  Remove processed items from the queue
-                        for (int i = 0; i < index + 2; i++)
+                        for (int i = 0; i < index + 2 && this._incoming.Count > 0; i++)
                         {
                             this._incoming.Dequeue();
                         }