diff options
author | Eugene Kenny <elkenny@gmail.com> | 2015-05-04 02:56:30 +0100 |
---|---|---|
committer | Eugene Kenny <elkenny@gmail.com> | 2016-03-11 15:30:25 +0000 |
commit | 1da352d06dac8ac3fa2fe0ceb4856c2203555134 (patch) | |
tree | 8f19758283b3eabcd4f28dbed61d18a8bf50eff8 /lib | |
parent | 9682f42c3020254edefdbc66acf421858163f005 (diff) | |
download | net-ssh-multi-1da352d06dac8ac3fa2fe0ceb4856c2203555134.tar.gz |
Use keepalive_interval option as IO select timeout
Net::SSH supports sending keepalive packets to the server to check
whether the connection is still alive. For this to work, IO#select needs
to be given a timeout so that the event loop can run periodically and
send the packets.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/ssh/multi/session.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/net/ssh/multi/session.rb b/lib/net/ssh/multi/session.rb index 2e2468f..409aeae 100644 --- a/lib/net/ssh/multi/session.rb +++ b/lib/net/ssh/multi/session.rb @@ -425,7 +425,7 @@ module Net; module SSH; module Multi # +false+ (the block returned +false+). def process(wait=nil, &block) realize_pending_connections! - wait = @connect_threads.any? ? 0 : wait + wait = @connect_threads.any? ? 0 : io_select_wait(wait) return false unless preprocess(&block) @@ -441,6 +441,15 @@ module Net; module SSH; module Multi end end + def io_select_wait(wait) + [wait, keepalive_interval].compact.min + end + + def keepalive_interval + servers = server_list.select { |s| s.options[:keepalive] } + servers.map { |s| s.options[:keepalive_interval] }.compact.min + end + # Runs the preprocess stage on all servers. Returns false if the block # returns false, and true if there either is no block, or it returns true. # This is called as part of the #process method. |