Skip to content

Commit b3ec023

Browse files
authored
Add Closed event to ShellStream. (#1332)
* Add `Closed` event to `ShellStream`. Lib consumer could hook to this event to detect if channel is closed by server **in time**. * handle `Closed` event on different thread. No need to block original thread.
1 parent 442f0a9 commit b3ec023

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Renci.SshNet/ShellStream.cs

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010

11+
using Renci.SshNet.Abstractions;
1112
using Renci.SshNet.Channels;
1213
using Renci.SshNet.Common;
1314

@@ -44,6 +45,11 @@ public class ShellStream : Stream
4445
/// </summary>
4546
public event EventHandler<ExceptionEventArgs>? ErrorOccurred;
4647

48+
/// <summary>
49+
/// Occurs when the channel was closed.
50+
/// </summary>
51+
public event EventHandler<EventArgs>? Closed;
52+
4753
/// <summary>
4854
/// Gets a value indicating whether data is available on the <see cref="ShellStream"/> to be read.
4955
/// </summary>
@@ -894,6 +900,12 @@ private void Session_Disconnected(object? sender, EventArgs e)
894900
private void Channel_Closed(object? sender, ChannelEventArgs e)
895901
{
896902
Dispose();
903+
904+
if (Closed != null)
905+
{
906+
// Handle event on different thread
907+
ThreadAbstraction.ExecuteThread(() => Closed?.Invoke(this, EventArgs.Empty));
908+
}
897909
}
898910

899911
private void Channel_DataReceived(object? sender, ChannelDataEventArgs e)

0 commit comments

Comments
 (0)