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 26 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 51 def closed? with_timeout { !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 40 def connected? with_timeout { listening? } end
Private Instance Methods
conn_completed?(sock)
click to toggle source
# File lib/selenium/webdriver/common/socket_poller.rb, line 105 def conn_completed?(sock) sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR).int.zero? end
current_time()
click to toggle source
# File lib/selenium/webdriver/common/socket_poller.rb, line 121 def current_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end
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 71 def listening? TCPSocket.new(@host, @port).close true rescue *NOT_CONNECTED_ERRORS false end
socket_writable?(sock)
click to toggle source
# File lib/selenium/webdriver/common/socket_poller.rb, line 101 def socket_writable?(sock) IO.select(nil, [sock], nil, CONNECT_TIMEOUT) end
with_timeout() { || ... }
click to toggle source
# File lib/selenium/webdriver/common/socket_poller.rb, line 109 def with_timeout max_time = current_time + @timeout until current_time > max_time return true if yield sleep @interval end false end