summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kenny <elkenny@gmail.com>2016-03-11 15:51:19 +0000
committerEugene Kenny <elkenny@gmail.com>2016-03-11 15:51:19 +0000
commit55b210c3a79699e908e07182029fa21f6eacc682 (patch)
tree606e9d3393dcda8c6af4bef677b39aa1db8c2c5f
parent97a3d4c2ee683848c397a579c3258bf179e77cc1 (diff)
downloadnet-ssh-55b210c3a79699e908e07182029fa21f6eacc682.tar.gz
Use minimum timeout when calling IO#select
If keepalive is enabled and the wait parameter is given when starting the event loop, we should pass the minimum of the two values through to IO#select. Otherwise the event loop could block for too long, and keepalive packets would not be sent as often as they should be.
-rw-r--r--lib/net/ssh/connection/session.rb8
-rw-r--r--test/connection/test_session.rb8
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/net/ssh/connection/session.rb b/lib/net/ssh/connection/session.rb
index c7fa881..65c7984 100644
--- a/lib/net/ssh/connection/session.rb
+++ b/lib/net/ssh/connection/session.rb
@@ -609,9 +609,11 @@ module Net; module SSH; module Connection
end
def io_select_wait(wait)
- return wait if wait
- return wait unless @keepalive.enabled?
- @keepalive.interval
+ if @keepalive.enabled?
+ [wait, @keepalive.interval].compact.min
+ else
+ wait
+ end
end
MAP = Constants.constants.inject({}) do |memo, name|
diff --git a/test/connection/test_session.rb b/test/connection/test_session.rb
index 4971d86..404d129 100644
--- a/test/connection/test_session.rb
+++ b/test/connection/test_session.rb
@@ -427,6 +427,14 @@ module Connection
session(options).process
end
+ def test_process_should_call_io_select_with_wait_if_provided_and_minimum
+ timeout = 10
+ wait = 5
+ options = { :keepalive => true, :keepalive_interval => timeout }
+ IO.expects(:select).with([socket],[],nil,wait).returns([[],[],[]])
+ session(options).process(wait)
+ end
+
def test_loop_should_call_process_until_process_returns_false
IO.stubs(:select).with([socket],[],nil,nil).returns([[],[],[]])
session.expects(:process).with(nil).times(4).returns(true,true,true,false).yields