Waiting till Socket connection completed
After `select` we should use `getsockopt` to read the SO_ERROR option at
level SOL_SOCKET to determine that connection completed successfully
@@ -71,7 +71,7 @@ module Selenium
begin
sock.connect_nonblock sockaddr
rescue Errno::EINPROGRESS
- retry if IO.select(nil, [sock], nil, CONNECT_TIMEOUT)
+ retry if socket_writable?(sock) && conn_completed?(sock)
raise Errno::ECONNREFUSED
rescue *CONNECTED_ERRORS
# yay!
@@ -85,6 +85,14 @@ module Selenium
false
end
+ def socket_writable?(sock)
+ IO.select(nil, [sock], nil, CONNECT_TIMEOUT)
+ end
+
+ def conn_completed?(sock)
+ sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR).int.zero?
+ end
+
def with_timeout
max_time = time_now + @timeout
