Bläddra i källkod

Added Read(Socket socket, int size, TimeSpan timeout) method.

Gert Driesen 7 år sedan
förälder
incheckning
7b43bdcce9
1 ändrade filer med 28 tillägg och 5 borttagningar
  1. 28 5
      src/Renci.SshNet/Abstractions/SocketAbstraction.cs

+ 28 - 5
src/Renci.SshNet/Abstractions/SocketAbstraction.cs

@@ -278,7 +278,30 @@ namespace Renci.SshNet.Abstractions
         }
 
         /// <summary>
-        /// Receives data from a bound <see cref="Socket"/>into a receive buffer.
+        /// Receives data from a bound <see cref="Socket"/>.
+        /// </summary>
+        /// <param name="socket"></param>
+        /// <param name="size">The number of bytes to receive.</param>
+        /// <param name="timeout">Specifies the amount of time after which the call will time out.</param>
+        /// <returns>
+        /// The bytes received.
+        /// </returns>
+        /// <remarks>
+        /// If no data is available for reading, the <see cref="Read(Socket, int, TimeSpan)"/> method will
+        /// block until data is available or the time-out value is exceeded. If the time-out value is exceeded, the
+        /// <see cref="Read(Socket, int, TimeSpan)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
+        ///  If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the
+        /// <see cref="Read(Socket, int, TimeSpan)"/> method will complete immediately and throw a <see cref="SocketException"/>.
+        /// </remarks>
+        public static byte[] Read(Socket socket, int size, TimeSpan timeout)
+        {
+            var buffer = new byte[size];
+            Read(socket, buffer, 0, size, timeout);
+            return buffer;
+        }
+
+        /// <summary>
+        /// Receives data from a bound <see cref="Socket"/> into a receive buffer.
         /// </summary>
         /// <param name="socket"></param>
         /// <param name="buffer">An array of type <see cref="byte"/> that is the storage location for the received data. </param>
@@ -289,11 +312,11 @@ namespace Renci.SshNet.Abstractions
         /// The number of bytes received.
         /// </returns>
         /// <remarks>
-        /// If no data is available for reading, the <see cref="Read(Socket,byte[], int, int, TimeSpan)"/> method will
-        /// block until data is available or the time-out value was exceeded. If the time-out value was exceeded, the
-        /// <see cref="Read(Socket,byte[], int, int, TimeSpan)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
+        /// If no data is available for reading, the <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> method will
+        /// block until data is available or the time-out value is exceeded. If the time-out value is exceeded, the
+        /// <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
         ///  If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the
-        /// <see cref="Read(Socket,byte[], int, int, TimeSpan)"/> method will complete immediately and throw a <see cref="SocketException"/>.
+        /// <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> method will complete immediately and throw a <see cref="SocketException"/>.
         /// </remarks>
         public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeSpan timeout)
         {