sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
MIT License
3.87k stars 915 forks source link

A couple of changes/fixes in SshCommand #1423

Closed Rob-Hague closed 1 week ago

Rob-Hague commented 1 week ago
  1. in CancelAsync, we were sending exit-signal channel request, when in fact we should be sending signal and the server will respond with exit-signal. This explains why we did not see any response or channel close in #1345 (@zeotuan fyi). Add a corresponding string? ExitSignal property which has a value when the server sends one. (closes #95 - seems like it existed once upon a time).
  2. Previously, we were setting the IAsyncResult.WaitHandle only when the command had completed successfully, or otherwise once EndExecute had been called. But we should be setting it as soon as the command completes whether successfully, with an error or via cancellation. This refactors the logic by removing the extra wait handles and consolidating the completion logic onto the IAsyncResult.WaitHandle. With this refactoring the logic intentionally looks (with some squinting) similar to a Task. Adding ExecuteAsync should only be a small step from here.
  3. Take a breaking change on ExitStatus by changing the return type from int to int?, in order to distinguish between an exit status of 0 and when no exit status has been returned (because for example, an exit signal was returned instead). This is the second commit.
WojciechNagorski commented 1 week ago

Is it ready for review?

Rob-Hague commented 1 week ago

Yes, thanks

Rob-Hague commented 1 week ago

Thanks