Skip to content

Commit

Permalink
Remove JRuby-specific SocketPoller#listening?
Browse files Browse the repository at this point in the history
The bug it worked around has been fixed in JRuby 1.6.7
(http://jruby.org/2012/02/22/jruby-1-6-7)
  • Loading branch information
p0deje committed Mar 6, 2019
1 parent 400c32a commit 287dbde
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 45 deletions.
49 changes: 19 additions & 30 deletions rb/lib/selenium/webdriver/common/socket_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,26 @@ def closed?
CONNECTED_ERRORS << Errno::EINVAL if Platform.windows?
CONNECTED_ERRORS << Errno::EALREADY if Platform.wsl?

if Platform.jruby?
# we use a plain TCPSocket here since JRuby has issues select()ing on a connecting socket
# see http://jira.codehaus.org/browse/JRUBY-5165
def listening?
TCPSocket.new(@host, @port).close
true
rescue *NOT_CONNECTED_ERRORS
false
end
else
def listening?
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])

begin
sock.connect_nonblock sockaddr
rescue Errno::EINPROGRESS
retry if IO.select(nil, [sock], nil, CONNECT_TIMEOUT)
raise Errno::ECONNREFUSED
rescue *CONNECTED_ERRORS
# yay!
end

sock.close
true
rescue *NOT_CONNECTED_ERRORS
sock.close if sock
WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}")
false
def listening?
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])

begin
sock.connect_nonblock sockaddr
rescue Errno::EINPROGRESS
retry if IO.select(nil, [sock], nil, CONNECT_TIMEOUT)
raise Errno::ECONNREFUSED
rescue *CONNECTED_ERRORS
# yay!
end

sock.close
true
rescue *NOT_CONNECTED_ERRORS
sock.close if sock
WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}")
false
end

def with_timeout
Expand Down
19 changes: 4 additions & 15 deletions rb/spec/unit/selenium/webdriver/socket_poller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,10 @@ module WebDriver
let(:socket) { double Socket, close: true }

def setup_connect(*states)
# TODO(jari): find a cleaner way to solve the platform-specific collaborators
if Platform.jruby?
states.each do |state|
if state
expect(TCPSocket).to receive(:new).and_return socket
else
expect(TCPSocket).to receive(:new).and_raise Errno::ECONNREFUSED
end
end
else
allow(Socket).to receive(:new).and_return socket
states.each do |state|
expect(socket).to receive(:connect_nonblock)
.and_raise(state ? Errno::EISCONN.new('connection in progress') : Errno::ECONNREFUSED.new('connection refused'))
end
allow(Socket).to receive(:new).and_return socket
states.each do |state|
expect(socket).to receive(:connect_nonblock)
.and_raise(state ? Errno::EISCONN.new('connection in progress') : Errno::ECONNREFUSED.new('connection refused'))
end
end

Expand Down

0 comments on commit 287dbde

Please sign in to comment.