# File lib/selenium/webdriver/common/socket_poller.rb, line 8 def initialize(host, port, timeout = 0, interval = 0.25) @host = host @port = Integer(port) @timeout = Integer(timeout) @interval = interval end
Returns true if the server has stopped listening within the given timeout, false otherwise.
@return [Boolean]
# File lib/selenium/webdriver/common/socket_poller.rb, line 33 def closed? with_timeout { not listening? } end
Returns true if the server is listening within the given timeout, false otherwise.
@return [Boolean]
# File lib/selenium/webdriver/common/socket_poller.rb, line 22 def connected? with_timeout { listening? } end
we use a plain TCPSocket here since JRuby has issues select()ing on a connecting socket see jira.codehaus.org/browse/JRUBY-5165
# File lib/selenium/webdriver/common/socket_poller.rb, line 50 def listening? TCPSocket.new(@host, @port).close true rescue *NOT_CONNECTED_ERRORS false end
# File lib/selenium/webdriver/common/socket_poller.rb, line 93 def wait sleep @interval end
# File lib/selenium/webdriver/common/socket_poller.rb, line 82 def with_timeout(&blk) max_time = Time.now + @timeout ( return true if yield wait ) until Time.now > max_time false end