ISubsystemSession.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using Microsoft.Extensions.Logging;
  5. using Renci.SshNet.Common;
  6. namespace Renci.SshNet
  7. {
  8. /// <summary>
  9. /// Base interface for SSH subsystem implementations.
  10. /// </summary>
  11. internal interface ISubsystemSession : IDisposable
  12. {
  13. /// <summary>
  14. /// Gets the logger factory for this subsystem session.
  15. /// </summary>
  16. /// <value>
  17. /// The logger factory for this connection. Will never return <see langword="null"/>.
  18. /// </value>
  19. public ILoggerFactory SessionLoggerFactory { get; }
  20. /// <summary>
  21. /// Gets or sets the number of milliseconds to wait for an operation to complete.
  22. /// </summary>
  23. /// <value>
  24. /// The number of milliseconds to wait for an operation to complete, or <c>-1</c> to wait indefinitely.
  25. /// </value>
  26. int OperationTimeout { get; set; }
  27. /// <summary>
  28. /// Gets a value indicating whether this session is open.
  29. /// </summary>
  30. /// <value>
  31. /// <see langword="true"/> if this session is open; otherwise, <see langword="false"/>.
  32. /// </value>
  33. bool IsOpen { get; }
  34. /// <summary>
  35. /// Connects the subsystem using a new SSH channel session.
  36. /// </summary>
  37. /// <exception cref="InvalidOperationException">The session is already connected.</exception>
  38. /// <exception cref="ObjectDisposedException">The method was called after the session was disposed.</exception>
  39. void Connect();
  40. /// <summary>
  41. /// Disconnects the subsystem channel.
  42. /// </summary>
  43. void Disconnect();
  44. /// <summary>
  45. /// Waits a specified time for a given <see cref="WaitHandle"/> to be signaled.
  46. /// </summary>
  47. /// <param name="waitHandle">The handle to wait for.</param>
  48. /// <param name="millisecondsTimeout">The number of milliseconds to wait for <paramref name="waitHandle"/> to be signaled, or <c>-1</c> to wait indefinitely.</param>
  49. /// <exception cref="SshException">The connection was closed by the server.</exception>
  50. /// <exception cref="SshException">The channel was closed.</exception>
  51. /// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
  52. void WaitOnHandle(WaitHandle waitHandle, int millisecondsTimeout);
  53. /// <summary>
  54. /// Asynchronously waits for a given <see cref="WaitHandle"/> to be signaled.
  55. /// </summary>
  56. /// <param name="waitHandle">The handle to wait for.</param>
  57. /// <param name="millisecondsTimeout">The number of milliseconds to wait for <paramref name="waitHandle"/> to be signaled, or <c>-1</c> to wait indefinitely.</param>
  58. /// <param name="cancellationToken">The cancellation token to observe.</param>
  59. /// <exception cref="SshException">The connection was closed by the server.</exception>
  60. /// <exception cref="SshException">The channel was closed.</exception>
  61. /// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
  62. /// <returns>A <see cref="Task"/> representing the wait.</returns>
  63. Task WaitOnHandleAsync(WaitHandle waitHandle, int millisecondsTimeout, CancellationToken cancellationToken);
  64. /// <summary>
  65. /// Asynchronously waits for a given <see cref="TaskCompletionSource{T}"/> to complete.
  66. /// </summary>
  67. /// <typeparam name="T">The type of the result which is being awaited.</typeparam>
  68. /// <param name="tcs">The handle to wait for.</param>
  69. /// <param name="millisecondsTimeout">The number of milliseconds to wait for <paramref name="tcs"/> to complete, or <c>-1</c> to wait indefinitely.</param>
  70. /// <param name="cancellationToken">The cancellation token to observe.</param>
  71. /// <exception cref="SshException">The connection was closed by the server.</exception>
  72. /// <exception cref="SshException">The channel was closed.</exception>
  73. /// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
  74. /// <returns>A <see cref="Task"/> representing the wait.</returns>
  75. Task<T> WaitOnHandleAsync<T>(TaskCompletionSource<T> tcs, int millisecondsTimeout, CancellationToken cancellationToken);
  76. /// <summary>
  77. /// Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed
  78. /// integer to specify the time interval.
  79. /// </summary>
  80. /// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray"/> - containing the objects to wait for.</param>
  81. /// <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>
  82. /// <returns>
  83. /// The array index of the first non-system object that satisfied the wait.
  84. /// </returns>
  85. /// <exception cref="SshException">The connection was closed by the server.</exception>
  86. /// <exception cref="SshException">The channel was closed.</exception>
  87. /// <exception cref="SshOperationTimeoutException">No object satisfied the wait and a time interval equivalent to <paramref name="millisecondsTimeout"/> has passed.</exception>
  88. /// <remarks>
  89. /// For the return value, the index of the first non-system object is considered to be zero.
  90. /// </remarks>
  91. int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout);
  92. /// <summary>
  93. /// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
  94. /// elements.
  95. /// </summary>
  96. /// <param name="waitHandle1">The first <see cref="WaitHandle"/> to wait for.</param>
  97. /// <param name="waitHandle2">The second <see cref="WaitHandle"/> to wait for.</param>
  98. /// <returns>
  99. /// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
  100. /// </returns>
  101. WaitHandle[] CreateWaitHandleArray(WaitHandle waitHandle1, WaitHandle waitHandle2);
  102. }
  103. }