You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add read timeout control to SshSession and error handling for channel timeouts
Introduce `SetReadTimeout` and `DisableReadTimeout` methods to manage channel read timeouts explicitly. Enhance `SshChannelStream` to throw `SshException` for read timeout errors.
Copy file name to clipboardExpand all lines: src/NullOpsDevs.LibSsh/SshSession.cs
+45Lines changed: 45 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -284,6 +284,24 @@ public unsafe void DisableSessionTimeout()
284
284
285
285
libssh2_session_set_timeout(SessionPtr,0);
286
286
}
287
+
288
+
/// <summary>
289
+
/// Disables the read timeout, allowing read operations to wait indefinitely for data.
290
+
/// </summary>
291
+
/// <remarks>
292
+
/// <para>By default, libssh2 has no read timeout. Use this method to explicitly disable any previously set read timeout.</para>
293
+
/// <para>The read timeout controls how long channel read operations (like reading command output) will wait for data before returning LIBSSH2_ERROR_TIMEOUT (-9).</para>
294
+
/// <para>The session must be in <see cref="SshConnectionStatus.Connected"/> or <see cref="SshConnectionStatus.LoggedIn"/> status before calling this method.</para>
/// Sets the maximum time to wait for data when reading from SSH channels.
331
+
/// </summary>
332
+
/// <param name="timeout">The timeout duration. Must be greater than zero and less than <see cref="int.MaxValue"/> milliseconds.</param>
333
+
/// <exception cref="ArgumentOutOfRangeException">Thrown if the timeout is negative or exceeds the maximum allowed value.</exception>
334
+
/// <remarks>
335
+
/// <para>This timeout applies specifically to channel read operations (e.g., reading command output via streaming).</para>
336
+
/// <para>If no data is received within the specified time, the read operation will return LIBSSH2_ERROR_TIMEOUT (-9).</para>
337
+
/// <para>This is separate from <see cref="SetSessionTimeout"/> which controls the overall session timeout.</para>
338
+
/// <para>The session must be in <see cref="SshConnectionStatus.Connected"/> or <see cref="SshConnectionStatus.LoggedIn"/> status before calling this method.</para>
339
+
/// </remarks>
340
+
/// <seealso cref="DisableReadTimeout"/>
341
+
/// <seealso cref="SetSessionTimeout"/>
342
+
publicunsafevoidSetReadTimeout(TimeSpantimeout)
343
+
{
344
+
if(timeout<TimeSpan.Zero)
345
+
thrownewArgumentOutOfRangeException(nameof(timeout),timeout,"Timeout must be greater than zero");
346
+
347
+
if(timeout.TotalMilliseconds>int.MaxValue)
348
+
thrownewArgumentOutOfRangeException(nameof(timeout),timeout,"Timeout cannot be greater than int.MaxValue milliseconds");
0 commit comments