Skip to content

Commit fb80bc6

Browse files
committed
test additions/tweaks
1 parent 1f7ad83 commit fb80bc6

File tree

6 files changed

+474
-359
lines changed

6 files changed

+474
-359
lines changed

src/Renci.SshNet/ISubsystemSession.cs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -58,57 +58,11 @@ internal interface ISubsystemSession : IDisposable
5858
/// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
5959
void WaitOnHandle(WaitHandle waitHandle, int millisecondsTimeout);
6060

61-
/// <summary>
62-
/// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
63-
/// 32-bit signed integer to specify the time interval in milliseconds.
64-
/// </summary>
65-
/// <param name="waitHandle">The handle to wait for.</param>
66-
/// <param name="millisecondsTimeout">To number of milliseconds to wait for <paramref name="waitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
67-
/// <returns>
68-
/// <see langword="true"/> if <paramref name="waitHandle"/> received a signal within the specified timeout;
69-
/// otherwise, <see langword="false"/>.
70-
/// </returns>
71-
/// <exception cref="SshException">The connection was closed by the server.</exception>
72-
/// <exception cref="SshException">The channel was closed.</exception>
73-
/// <remarks>
74-
/// The blocking wait is also interrupted when either the established channel is closed, the current
75-
/// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
76-
/// or session event.
77-
/// </remarks>
78-
bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout);
79-
80-
/// <summary>
81-
/// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
82-
/// 32-bit signed integer to specify the time interval in milliseconds.
83-
/// </summary>
84-
/// <param name="waitHandleA">The first handle to wait for.</param>
85-
/// <param name="waitHandleB">The second handle to wait for.</param>
86-
/// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
87-
/// <returns>
88-
/// <c>0</c> if <paramref name="waitHandleA"/> received a signal within the specified timeout and <c>1</c>
89-
/// if <paramref name="waitHandleB"/> received a signal within the specified timeout, or <see cref="WaitHandle.WaitTimeout"/>
90-
/// if no object satisfied the wait.
91-
/// </returns>
92-
/// <exception cref="SshException">The connection was closed by the server.</exception>
93-
/// <exception cref="SshException">The channel was closed.</exception>
94-
/// <remarks>
95-
/// <para>
96-
/// The blocking wait is also interrupted when either the established channel is closed, the current
97-
/// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
98-
/// or session event.
99-
/// </para>
100-
/// <para>
101-
/// When both <paramref name="waitHandleA"/> and <paramref name="waitHandleB"/> are signaled during the call,
102-
/// then <c>0</c> is returned.
103-
/// </para>
104-
/// </remarks>
105-
int WaitAny(WaitHandle waitHandleA, WaitHandle waitHandleB, int millisecondsTimeout);
106-
10761
/// <summary>
10862
/// Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed
10963
/// integer to specify the time interval.
11064
/// </summary>
111-
/// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray(WaitHandle[])"/> - containing the objects to wait for.</param>
65+
/// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray"/> - containing the objects to wait for.</param>
11266
/// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
11367
/// <returns>
11468
/// The array index of the first non-system object that satisfied the wait.
@@ -121,16 +75,6 @@ internal interface ISubsystemSession : IDisposable
12175
/// </remarks>
12276
int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout);
12377

124-
/// <summary>
125-
/// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
126-
/// elements.
127-
/// </summary>
128-
/// <param name="waitHandles">A <see cref="WaitHandle"/> array containing the objects to wait for.</param>
129-
/// <returns>
130-
/// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
131-
/// </returns>
132-
WaitHandle[] CreateWaitHandleArray(params WaitHandle[] waitHandles);
133-
13478
/// <summary>
13579
/// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
13680
/// elements.

src/Renci.SshNet/Sftp/ISftpSession.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal interface ISftpSession : ISubsystemSession
4040
/// <param name="path">The new working directory.</param>
4141
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
4242
/// <returns>A <see cref="Task"/> that tracks the asynchronous change working directory request.</returns>
43-
Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default);
43+
Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken);
4444

4545
/// <summary>
4646
/// Resolves a given path into an absolute path on the server.
@@ -168,7 +168,7 @@ internal interface ISftpSession : ISubsystemSession
168168
/// <param name="path">The path.</param>
169169
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
170170
/// <returns>A <see cref="Task"/> that represents the asynchronous <c>SSH_FXP_MKDIR</c> operation.</returns>
171-
Task RequestMkDirAsync(string path, CancellationToken cancellationToken = default);
171+
Task RequestMkDirAsync(string path, CancellationToken cancellationToken);
172172

173173
/// <summary>
174174
/// Performs a <c>SSH_FXP_OPEN</c> request.
@@ -389,7 +389,7 @@ internal interface ISftpSession : ISubsystemSession
389389
/// <returns>
390390
/// A task that represents the asynchronous <c>SSH_FXP_RMDIR</c> request.
391391
/// </returns>
392-
Task RequestRmDirAsync(string path, CancellationToken cancellationToken = default);
392+
Task RequestRmDirAsync(string path, CancellationToken cancellationToken);
393393

394394
/// <summary>
395395
/// Performs SSH_FXP_SETSTAT request.

src/Renci.SshNet/Sftp/SftpSession.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void ChangeDirectory(string path)
9090
/// <param name="path">The new working directory.</param>
9191
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
9292
/// <returns>A <see cref="Task"/> that tracks the asynchronous change working directory request.</returns>
93-
public async Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default)
93+
public async Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken)
9494
{
9595
cancellationToken.ThrowIfCancellationRequested();
9696

@@ -1469,7 +1469,7 @@ public void RequestMkDir(string path)
14691469
/// <param name="path">The path.</param>
14701470
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
14711471
/// <returns>A <see cref="Task"/> that represents the asynchronous <c>SSH_FXP_MKDIR</c> operation.</returns>
1472-
public Task RequestMkDirAsync(string path, CancellationToken cancellationToken = default)
1472+
public Task RequestMkDirAsync(string path, CancellationToken cancellationToken)
14731473
{
14741474
if (cancellationToken.IsCancellationRequested)
14751475
{
@@ -1529,7 +1529,7 @@ public void RequestRmDir(string path)
15291529
}
15301530

15311531
/// <inheritdoc />
1532-
public Task RequestRmDirAsync(string path, CancellationToken cancellationToken = default)
1532+
public Task RequestRmDirAsync(string path, CancellationToken cancellationToken)
15331533
{
15341534
if (cancellationToken.IsCancellationRequested)
15351535
{

src/Renci.SshNet/SubsystemSession.cs

Lines changed: 3 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal abstract class SubsystemSession : ISubsystemSession
1818
{
1919
/// <summary>
2020
/// Holds the number of system wait handles that are returned as the leading entries in the array returned
21-
/// in <see cref="CreateWaitHandleArray(WaitHandle[])"/>.
21+
/// in <see cref="CreateWaitHandleArray"/>.
2222
/// </summary>
2323
private const int SystemWaitHandleCount = 3;
2424

@@ -310,124 +310,7 @@ protected async Task<T> WaitOnHandleAsync<T>(TaskCompletionSource<T> tcs, int mi
310310
}
311311
}
312312

313-
/// <summary>
314-
/// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
315-
/// 32-bit signed integer to specify the time interval in milliseconds.
316-
/// </summary>
317-
/// <param name="waitHandle">The handle to wait for.</param>
318-
/// <param name="millisecondsTimeout">To number of milliseconds to wait for <paramref name="waitHandle"/> to get signaled, or -1 to wait indefinitely.</param>
319-
/// <returns>
320-
/// <see langword="true"/> if <paramref name="waitHandle"/> received a signal within the specified timeout;
321-
/// otherwise, <see langword="false"/>.
322-
/// </returns>
323-
/// <exception cref="SshException">The connection was closed by the server.</exception>
324-
/// <exception cref="SshException">The channel was closed.</exception>
325-
/// <remarks>
326-
/// The blocking wait is also interrupted when either the established channel is closed, the current
327-
/// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
328-
/// or session event.
329-
/// </remarks>
330-
public bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout)
331-
{
332-
var waitHandles = new[]
333-
{
334-
_errorOccurredWaitHandle,
335-
_sessionDisconnectedWaitHandle,
336-
_channelClosedWaitHandle,
337-
waitHandle
338-
};
339-
340-
var result = WaitHandle.WaitAny(waitHandles, millisecondsTimeout);
341-
switch (result)
342-
{
343-
case 0:
344-
ExceptionDispatchInfo.Capture(_exception).Throw();
345-
return false; // unreached
346-
case 1:
347-
throw new SshException("Connection was closed by the server.");
348-
case 2:
349-
throw new SshException("Channel was closed.");
350-
case 3:
351-
return true;
352-
case WaitHandle.WaitTimeout:
353-
return false;
354-
default:
355-
throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "WaitAny return value '{0}' is not implemented.", result));
356-
}
357-
}
358-
359-
/// <summary>
360-
/// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
361-
/// 32-bit signed integer to specify the time interval in milliseconds.
362-
/// </summary>
363-
/// <param name="waitHandleA">The first handle to wait for.</param>
364-
/// <param name="waitHandleB">The second handle to wait for.</param>
365-
/// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or -1 to wait indefinitely.</param>
366-
/// <returns>
367-
/// <c>0</c> if <paramref name="waitHandleA"/> received a signal within the specified timeout, and <c>1</c>
368-
/// if <paramref name="waitHandleB"/> received a signal within the specified timeout.
369-
/// </returns>
370-
/// <exception cref="SshException">The connection was closed by the server.</exception>
371-
/// <exception cref="SshException">The channel was closed.</exception>
372-
/// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
373-
/// <remarks>
374-
/// <para>
375-
/// The blocking wait is also interrupted when either the established channel is closed, the current
376-
/// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
377-
/// or session event.
378-
/// </para>
379-
/// <para>
380-
/// When both <paramref name="waitHandleA"/> and <paramref name="waitHandleB"/> are signaled during the call,
381-
/// then <c>0</c> is returned.
382-
/// </para>
383-
/// </remarks>
384-
public int WaitAny(WaitHandle waitHandleA, WaitHandle waitHandleB, int millisecondsTimeout)
385-
{
386-
var waitHandles = new[]
387-
{
388-
_errorOccurredWaitHandle,
389-
_sessionDisconnectedWaitHandle,
390-
_channelClosedWaitHandle,
391-
waitHandleA,
392-
waitHandleB
393-
};
394-
395-
var result = WaitHandle.WaitAny(waitHandles, millisecondsTimeout);
396-
switch (result)
397-
{
398-
case 0:
399-
ExceptionDispatchInfo.Capture(_exception).Throw();
400-
return -1; // unreached
401-
case 1:
402-
throw new SshException("Connection was closed by the server.");
403-
case 2:
404-
throw new SshException("Channel was closed.");
405-
case 3:
406-
return 0;
407-
case 4:
408-
return 1;
409-
case WaitHandle.WaitTimeout:
410-
throw new SshOperationTimeoutException("Operation has timed out.");
411-
default:
412-
throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "WaitAny return value '{0}' is not implemented.", result));
413-
}
414-
}
415-
416-
/// <summary>
417-
/// Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed
418-
/// integer to specify the time interval.
419-
/// </summary>
420-
/// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray(WaitHandle[])"/> - containing the objects to wait for.</param>
421-
/// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or -1 to wait indefinitely.</param>
422-
/// <returns>
423-
/// The array index of the first non-system object that satisfied the wait.
424-
/// </returns>
425-
/// <exception cref="SshException">The connection was closed by the server.</exception>
426-
/// <exception cref="SshException">The channel was closed.</exception>
427-
/// <exception cref="SshOperationTimeoutException">No object satisfied the wait and a time interval equivalent to <paramref name="millisecondsTimeout"/> has passed.</exception>
428-
/// <remarks>
429-
/// For the return value, the index of the first non-system object is considered to be zero.
430-
/// </remarks>
313+
/// <inheritdoc/>
431314
public int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout)
432315
{
433316
var result = WaitHandle.WaitAny(waitHandles, millisecondsTimeout);
@@ -447,15 +330,7 @@ public int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout)
447330
}
448331
}
449332

450-
/// <summary>
451-
/// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
452-
/// elements.
453-
/// </summary>
454-
/// <param name="waitHandle1">The first <see cref="WaitHandle"/> to wait for.</param>
455-
/// <param name="waitHandle2">The second <see cref="WaitHandle"/> to wait for.</param>
456-
/// <returns>
457-
/// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
458-
/// </returns>
333+
/// <inheritdoc/>
459334
public WaitHandle[] CreateWaitHandleArray(WaitHandle waitHandle1, WaitHandle waitHandle2)
460335
{
461336
return new WaitHandle[]
@@ -468,29 +343,6 @@ public WaitHandle[] CreateWaitHandleArray(WaitHandle waitHandle1, WaitHandle wai
468343
};
469344
}
470345

471-
/// <summary>
472-
/// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
473-
/// elements.
474-
/// </summary>
475-
/// <param name="waitHandles">A <see cref="WaitHandle"/> array containing the objects to wait for.</param>
476-
/// <returns>
477-
/// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
478-
/// </returns>
479-
public WaitHandle[] CreateWaitHandleArray(params WaitHandle[] waitHandles)
480-
{
481-
var array = new WaitHandle[waitHandles.Length + SystemWaitHandleCount];
482-
array[0] = _errorOccurredWaitHandle;
483-
array[1] = _sessionDisconnectedWaitHandle;
484-
array[2] = _channelClosedWaitHandle;
485-
486-
for (var i = 0; i < waitHandles.Length; i++)
487-
{
488-
array[i + SystemWaitHandleCount] = waitHandles[i];
489-
}
490-
491-
return array;
492-
}
493-
494346
private void Session_Disconnected(object sender, EventArgs e)
495347
{
496348
_ = _sessionDisconnectedWaitHandle?.Set();

0 commit comments

Comments
 (0)