Skip to content
Closed
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
32 changes: 32 additions & 0 deletions src/Renci.SshNet/ShellStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public class ShellStream : Stream
/// </summary>
public event EventHandler<ExceptionEventArgs> ErrorOccurred;

/// <summary>
/// Occurs when the connection is closed.
/// </summary>
public event EventHandler<EventArgs> Closed;

/// <summary>
/// Occurs when the session is disconnected.
/// </summary>
public event EventHandler<EventArgs> Disconnected;

/// <summary>
/// Gets a value that indicates whether data is available on the <see cref="ShellStream"/> to be read.
/// </summary>
Expand Down Expand Up @@ -766,12 +776,16 @@ private void Session_ErrorOccured(object sender, ExceptionEventArgs e)

private void Session_Disconnected(object sender, EventArgs e)
{
OnDisconnected();

if (_channel != null)
_channel.Dispose();
}

private void Channel_Closed(object sender, ChannelEventArgs e)
{
OnClosed();

// TODO: Do we need to call dispose here ??
Dispose();
}
Expand Down Expand Up @@ -807,5 +821,23 @@ private void OnDataReceived(byte[] data)
handler(this, new ShellDataEventArgs(data));
}
}

private void OnClosed()
{
var handler = Closed;
if(Closed != null)
{
handler(this, EventArgs.Empty);
}
}

private void OnDisconnected()
{
var handler = Disconnected;
if(Disconnected != null)
{
handler(this, EventArgs.Empty);
}
}
}
}