Sha256: 65a8a01dd65d2491d9e5251756d0ef93417d15a2a42497c16b259419e9ee0395

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

# http://groups.google.com/group/capistrano/browse_thread/thread/455c0c8a6faa9cc8?pli=1
class Net::SSH::Gateway
  # Opens a SSH tunnel from a port on a remote host to a given host and port
  # on the local side
  # (equivalent to openssh -R parameter)
  def open_remote(port, host, remote_port, remote_host = "127.0.0.1")
    ensure_open!

    begin
      @session_mutex.synchronize do
        result = @session.forward.remote(port, host, remote_port, remote_host)
      end
      
      if block_given?
        begin
          yield [remote_port, remote_host]
        ensure
          close_remote(remote_port, remote_host)
        end
      else
        return [remote_port, remote_host]
      end
    rescue Errno::EADDRINUSE
      retry
    end
  end

  # Cancels port-forwarding over an open port that was previously opened via
  # #open_remote.
  def close_remote(port, host = "127.0.0.1")
    puts "Close the remote port #{host}:#{port}!"
    ensure_open!

    @session_mutex.synchronize do
      @session.forward.cancel_remote(port, host)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sauce-0.10.0 lib/sauce/gateway_ext.rb
sauce-0.9.0 lib/sauce/gateway_ext.rb
sauce-0.8.0 lib/sauce/gateway_ext.rb
sauce-0.7.2 lib/sauce/gateway_ext.rb
sauce-0.7.1 lib/sauce/gateway_ext.rb
sauce-0.7.0 lib/sauce/gateway_ext.rb
sauce-0.6.3 lib/sauce/gateway_ext.rb
sauce-0.6.2 lib/sauce/gateway_ext.rb
sauce-0.6.1 lib/sauce/gateway_ext.rb
sauce-0.6.0 lib/sauce/gateway_ext.rb
sauce-0.5.0 lib/gateway_ext.rb
sauce-0.4.3 lib/gateway_ext.rb