protected override void Close()
{
var forwardedPort = _forwardedPort;
if (forwardedPort != null)
{
forwardedPort.Closing -= ForwardedPort_Closing;
_forwardedPort = null;
}
// signal to the server that we will not send anything anymore; this will also interrupt the
// blocking receive in Bind if the server sends FIN/ACK in time
//
// if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed
ShutdownSocket(SocketShutdown.Send);
// close the SSH channel, and mark the channel closed
base.Close();
// close the socket
CloseSocket();
}