Skip to content

Commit 7b43bdc

Browse files
committed
Added Read(Socket socket, int size, TimeSpan timeout) method.
1 parent 4f5aaec commit 7b43bdc

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/Renci.SshNet/Abstractions/SocketAbstraction.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,30 @@ public static void SendByte(Socket socket, byte value)
278278
}
279279

280280
/// <summary>
281-
/// Receives data from a bound <see cref="Socket"/>into a receive buffer.
281+
/// Receives data from a bound <see cref="Socket"/>.
282+
/// </summary>
283+
/// <param name="socket"></param>
284+
/// <param name="size">The number of bytes to receive.</param>
285+
/// <param name="timeout">Specifies the amount of time after which the call will time out.</param>
286+
/// <returns>
287+
/// The bytes received.
288+
/// </returns>
289+
/// <remarks>
290+
/// If no data is available for reading, the <see cref="Read(Socket, int, TimeSpan)"/> method will
291+
/// block until data is available or the time-out value is exceeded. If the time-out value is exceeded, the
292+
/// <see cref="Read(Socket, int, TimeSpan)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
293+
/// If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the
294+
/// <see cref="Read(Socket, int, TimeSpan)"/> method will complete immediately and throw a <see cref="SocketException"/>.
295+
/// </remarks>
296+
public static byte[] Read(Socket socket, int size, TimeSpan timeout)
297+
{
298+
var buffer = new byte[size];
299+
Read(socket, buffer, 0, size, timeout);
300+
return buffer;
301+
}
302+
303+
/// <summary>
304+
/// Receives data from a bound <see cref="Socket"/> into a receive buffer.
282305
/// </summary>
283306
/// <param name="socket"></param>
284307
/// <param name="buffer">An array of type <see cref="byte"/> that is the storage location for the received data. </param>
@@ -289,11 +312,11 @@ public static void SendByte(Socket socket, byte value)
289312
/// The number of bytes received.
290313
/// </returns>
291314
/// <remarks>
292-
/// If no data is available for reading, the <see cref="Read(Socket,byte[], int, int, TimeSpan)"/> method will
293-
/// block until data is available or the time-out value was exceeded. If the time-out value was exceeded, the
294-
/// <see cref="Read(Socket,byte[], int, int, TimeSpan)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
315+
/// If no data is available for reading, the <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> method will
316+
/// block until data is available or the time-out value is exceeded. If the time-out value is exceeded, the
317+
/// <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
295318
/// If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the
296-
/// <see cref="Read(Socket,byte[], int, int, TimeSpan)"/> method will complete immediately and throw a <see cref="SocketException"/>.
319+
/// <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> method will complete immediately and throw a <see cref="SocketException"/>.
297320
/// </remarks>
298321
public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeSpan timeout)
299322
{

0 commit comments

Comments
 (0)