浏览代码

Ensure only one SSH_MSG_CHANNEL_CLOSE message per channel is sent

olegkap_cp 13 年之前
父节点
当前提交
7fd452a678
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      Renci.SshClient/Renci.SshNet/Channels/Channel.cs

+ 12 - 2
Renci.SshClient/Renci.SshNet/Channels/Channel.cs

@@ -20,6 +20,8 @@ namespace Renci.SshNet.Channels
 
         private EventWaitHandle _disconnectedWaitHandle = new ManualResetEvent(false);
 
+        private bool _closeMessageSent = false;
+
         private uint _initialWindowSize = 0x100000;
 
         private uint _maximumPacketSize = 0x8000;
@@ -216,7 +218,11 @@ namespace Renci.SshNet.Channels
         public virtual void Close()
         {
             //  Send message to close the channel on the server
-            this.SendMessage(new ChannelCloseMessage(this.RemoteChannelNumber));
+            if (!_closeMessageSent)
+            {
+                this.SendMessage(new ChannelCloseMessage(this.RemoteChannelNumber));
+                this._closeMessageSent = true;
+            }
 
             //  Wait for channel to be closed
             this._session.WaitHandle(this._channelClosedWaitHandle);
@@ -332,7 +338,11 @@ namespace Renci.SshNet.Channels
             this._session.Disconnected -= Session_Disconnected;
 
             //  Send close message to channel to confirm channel closing
-            this.SendMessage(new ChannelCloseMessage(this.RemoteChannelNumber));
+            if (!_closeMessageSent)
+            {
+                this.SendMessage(new ChannelCloseMessage(this.RemoteChannelNumber));
+                this._closeMessageSent = true;
+            }
             
             if (this.Closed != null)
             {