Class: Selenium::WebDriver::SocketPoller
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/socket_poller.rb |
Constant Summary
-
CONNECTED_ERRORS =
# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 63[Errno::EISCONN].tap { |arr| arr << Errno::EINVAL if Platform.windows? arr << Errno::EALREADY if Platform.wsl? }.freeze
-
CONNECT_TIMEOUT =
# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 575
-
NOT_CONNECTED_ERRORS =
# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 59[Errno::ECONNREFUSED, Errno::ENOTCONN, SocketError].tap { |arr| arr << Errno::EPERM if Platform.cygwin? }.freeze
Class Method Summary
Instance Attribute Summary
-
#closed? ⇒ Boolean
readonly
Returns true if the server has stopped listening within the given timeout, false otherwise.
-
#connected? ⇒ Boolean
readonly
Returns true if the server is listening within the given timeout, false otherwise.
-
#listening? ⇒ Boolean
readonly
private
we use a plain TCPSocket here since JRuby has issues closing socket see github.com/jruby/jruby/issues/5709.
Instance Method Summary
- #conn_completed?(sock) ⇒ Boolean private
- #current_time private
- #socket_writable?(sock) ⇒ Boolean private
- #with_timeout private
Constructor Details
.new(host, port, timeout = 0, interval = 0.25) ⇒ SocketPoller
# File 'rb/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
Instance Attribute Details
#closed? ⇒ Boolean
(readonly)
Returns true if the server has stopped listening within the given timeout, false otherwise.
# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 51
def closed? with_timeout { !listening? } end
#connected? ⇒ Boolean
(readonly)
Returns true if the server is listening within the given timeout, false otherwise.
# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 40
def connected? with_timeout { listening? } end
#listening? ⇒ Boolean
(readonly, private)
we use a plain TCPSocket here since JRuby has issues closing socket see github.com/jruby/jruby/issues/5709
See additional method definition at line 71.
# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 78
def listening? TCPSocket.new(@host, @port).close true rescue *NOT_CONNECTED_ERRORS false end
Instance Method Details
#conn_completed?(sock) ⇒ Boolean
(private)
# File 'rb/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 (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 121
def current_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end
#socket_writable?(sock) ⇒ Boolean
(private)
# File 'rb/lib/selenium/webdriver/common/socket_poller.rb', line 101
def socket_writable?(sock) sock.wait_writable(CONNECT_TIMEOUT) end
#with_timeout (private)
[ GitHub ]# File 'rb/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