浏览代码

Do not catching exceptions while clearing read buffer of socket.
Leave this up to the caller.

drieseng 9 年之前
父节点
当前提交
77e7bc8c04
共有 1 个文件被更改,包括 6 次插入11 次删除
  1. 6 11
      src/Renci.SshNet/Abstractions/SocketAbstraction.cs

+ 6 - 11
src/Renci.SshNet/Abstractions/SocketAbstraction.cs

@@ -81,20 +81,15 @@ namespace Renci.SshNet.Abstractions
 
         public static void ClearReadBuffer(Socket socket)
         {
-            try
-            {
-                var buffer = new byte[256];
-                int bytesReceived;
+            var timeout = TimeSpan.FromMilliseconds(10);
+            var buffer = new byte[256];
+            int bytesReceived;
 
-                do
-                {
-                    bytesReceived = ReadPartial(socket, buffer, 0, buffer.Length, TimeSpan.FromMilliseconds(10));
-                } while (bytesReceived > 0);
-            }
-            catch
+            do
             {
-                // ignore any exceptions
+                bytesReceived = ReadPartial(socket, buffer, 0, buffer.Length, timeout);
             }
+            while (bytesReceived > 0);
         }
 
         public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size, TimeSpan timeout)