Browse Source

Lock _incoming object where performing Enqueue
Rollback previouse commit

olegkap_cp 12 năm trước cách đây
mục cha
commit
4df7a2849b
1 tập tin đã thay đổi với 10 bổ sung22 xóa
  1. 10 22
      Renci.SshClient/Renci.SshNet/ShellStream.cs

+ 10 - 22
Renci.SshClient/Renci.SshNet/ShellStream.cs

@@ -281,10 +281,7 @@ namespace Renci.SshNet
                 {
                     if (this._incoming.Count > 0)
                     {
-                        lock (this._encoding)
-                        {
-                            text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
-                        }
+                        text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
                     }
 
                     if (text.Length > 0)
@@ -398,10 +395,7 @@ namespace Renci.SshNet
 
                             if (this._incoming.Count > 0)
                             {
-                                lock (this._encoding)
-                                {
-                                    text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
-                                }
+                                text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
                             }
 
                             if (text.Length > 0)
@@ -533,10 +527,7 @@ namespace Renci.SshNet
                 {
                     if (this._incoming.Count > 0)
                     {
-                        lock (this._encoding)
-                        {
-                            text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
-                        }
+                        text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
                     }
 
                     var match = regex.Match(text);
@@ -595,10 +586,7 @@ namespace Renci.SshNet
                 {
                     if (this._incoming.Count > 0)
                     {
-                        lock (this._encoding)
-                        {
-                            text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
-                        }
+                        text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
                     }
 
                     var index = text.IndexOf("\r\n");
@@ -643,10 +631,7 @@ namespace Renci.SshNet
 
             lock (this._incoming)
             {
-                lock (this._encoding)
-                {
-                    text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
-                }
+                text = this._encoding.GetString(this._incoming.ToArray(), 0, this._incoming.Count);
                 this._incoming.Clear();
             }
 
@@ -740,9 +725,12 @@ namespace Renci.SshNet
 
         private void Channel_DataReceived(object sender, ChannelDataEventArgs e)
         {
-            foreach (var b in e.Data)
+            lock (this._incoming)
             {
-                _incoming.Enqueue(b);
+                foreach (var b in e.Data)
+                {
+                    this._incoming.Enqueue(b);
+                }
             }
 
             this._dataReceived.Set();