Skip to content

Add Closed event to ShellStream. #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Renci.SshNet/ShellStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;

using Renci.SshNet.Abstractions;
using Renci.SshNet.Channels;
using Renci.SshNet.Common;

Expand Down Expand Up @@ -44,6 +45,11 @@ public class ShellStream : Stream
/// </summary>
public event EventHandler<ExceptionEventArgs>? ErrorOccurred;

/// <summary>
/// Occurs when the channel was closed.
/// </summary>
public event EventHandler<EventArgs>? Closed;

/// <summary>
/// Gets a value indicating whether data is available on the <see cref="ShellStream"/> to be read.
/// </summary>
Expand Down Expand Up @@ -894,6 +900,12 @@ private void Session_Disconnected(object? sender, EventArgs e)
private void Channel_Closed(object? sender, ChannelEventArgs e)
{
Dispose();

if (Closed != null)
{
// Handle event on different thread
ThreadAbstraction.ExecuteThread(() => Closed?.Invoke(this, EventArgs.Empty));
}
}

private void Channel_DataReceived(object? sender, ChannelDataEventArgs e)
Expand Down