class Selenium::WebDriver::SocketPoller
Constants
- CONNECTED_ERRORS
- CONNECT_TIMEOUT
- NOT_CONNECTED_ERRORS
Public Class Methods
new(host, port, timeout = 0, interval = 0.25)
click to toggle source
# 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 = Float(timeout) @interval = interval end
Public Instance Methods
closed?()
click to toggle source
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
connected?()
click to toggle source
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
Private Instance Methods
listening?()
click to toggle source
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
time_now()
click to toggle source
for testability
# File lib/selenium/webdriver/common/socket_poller.rb, line 99 def time_now Time.now end
wait()
click to toggle source
# File lib/selenium/webdriver/common/socket_poller.rb, line 94 def wait sleep @interval end
with_timeout() { || ... }
click to toggle source
# File lib/selenium/webdriver/common/socket_poller.rb, line 83 def with_timeout(&blk) max_time = time_now + @timeout ( return true if yield wait ) until time_now > max_time false end