diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/ssh/gateway.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/net/ssh/gateway.rb b/lib/net/ssh/gateway.rb index 897291f..9742db9 100644 --- a/lib/net/ssh/gateway.rb +++ b/lib/net/ssh/gateway.rb @@ -111,25 +111,28 @@ class Net::SSH::Gateway # port = gateway.open('host', 80) # # ... # gateway.close(port) - def open(host, port) + # + # If +local_port+ is not specified, the next available port will be used. + def open(host, port, local_port=nil) ensure_open! - local_port = next_port + actual_local_port = local_port || next_port @session_mutex.synchronize do - @session.forward.local(local_port, host, port) + @session.forward.local(actual_local_port, host, port) end if block_given? begin - yield local_port + yield actual_local_port ensure - close(local_port) + close(actual_local_port) end else - return local_port + return actual_local_port end rescue Errno::EADDRINUSE + raise if local_port # if a local port was explicitly requested, bubble the error up retry end @@ -186,7 +189,9 @@ class Net::SSH::Gateway @thread = Thread.new do while @active - @session_mutex.synchronize { @session.process(0.1) } + @session_mutex.synchronize do + @session.process(0.1) + end end end end @@ -200,4 +205,4 @@ class Net::SSH::Gateway port end end -end
\ No newline at end of file +end |