using System; using System.Threading; namespace Renci.SshNet { /// /// Provides functionality for local port forwarding /// public partial class ForwardedPortLocal : ForwardedPort, IDisposable { private EventWaitHandle _listenerTaskCompleted; /// /// Gets the bound host. /// public string BoundHost { get; protected set; } /// /// Gets the bound port. /// public uint BoundPort { get; protected set; } /// /// Gets the forwarded host. /// public string Host { get; protected set; } /// /// Gets the forwarded port. /// public uint Port { get; protected set; } /// /// Initializes a new instance of the class. /// /// The bound port. /// The host. /// The port. /// is greater than . /// is null. /// is greater than . /// /// /// public ForwardedPortLocal(uint boundPort, string host, uint port) : this(string.Empty, boundPort, host, port) { } /// /// Initializes a new instance of the class. /// /// The bound host. /// The host. /// The port. /// is null. /// is null. /// is greater than . public ForwardedPortLocal(string boundHost, string host, uint port) : this(boundHost, 0, host, port) { } /// /// Initializes a new instance of the class. /// /// The bound host. /// The bound port. /// The host. /// The port. /// is null. /// is null. /// is greater than . /// is greater than . public ForwardedPortLocal(string boundHost, uint boundPort, string host, uint port) { if (boundHost == null) throw new ArgumentNullException("boundHost"); if (host == null) throw new ArgumentNullException("host"); boundPort.ValidatePort("boundPort"); port.ValidatePort("port"); this.BoundHost = boundHost; this.BoundPort = boundPort; this.Host = host; this.Port = port; } /// /// Starts local port forwarding. /// public override void Start() { this.InternalStart(); } /// /// Stops local port forwarding. /// public override void Stop() { base.Stop(); this.InternalStop(); } partial void InternalStart(); partial void InternalStop(); partial void ExecuteThread(Action action); #region IDisposable Members private bool _isDisposed; /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged ResourceMessages. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Releases unmanaged and - optionally - managed resources /// /// true to release both managed and unmanaged resources; false to release only unmanaged ResourceMessages. protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this._isDisposed) { this.InternalStop(); // If disposing equals true, dispose all managed // and unmanaged ResourceMessages. if (disposing) { // Dispose managed ResourceMessages. if (this._listenerTaskCompleted != null) { this._listenerTaskCompleted.Dispose(); this._listenerTaskCompleted = null; } } // Note disposing has been done. _isDisposed = true; } } /// /// Releases unmanaged resources and performs other cleanup operations before the /// is reclaimed by garbage collection. /// ~ForwardedPortLocal() { // Do not re-create Dispose clean-up code here. // Calling Dispose(false) is optimal in terms of // readability and maintainability. Dispose(false); } #endregion } }