From 65a1ecc42d4ab4c633e6487b8cb932637e7505c1 Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Thu, 31 May 2012 16:27:33 -0400 Subject: [PATCH] RUBY-441 Remove connect_nonblock from tcp_socket implementation to reduce problems due to inconsistent implementation in JRuby and Windows. Connection timeouts are now reverted to using the timeout module for all platforms. --- lib/mongo/util/tcp_socket.rb | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/lib/mongo/util/tcp_socket.rb b/lib/mongo/util/tcp_socket.rb index bdbcdf7..384e82a 100644 --- a/lib/mongo/util/tcp_socket.rb +++ b/lib/mongo/util/tcp_socket.rb @@ -1,4 +1,5 @@ require 'socket' +require 'timeout' module Mongo # Wrapper class for Socket @@ -25,34 +26,12 @@ module Mongo end def connect - # Connect nonblock is broken in current versions of JRuby - if RUBY_PLATFORM == 'java' - require 'timeout' - if @connect_timeout - Timeout::timeout(@connect_timeout, OperationTimeout) do - @socket.connect(@socket_address) - end - else + if @connect_timeout + Timeout::timeout(@connect_timeout, OperationTimeout) do @socket.connect(@socket_address) end else - # Try to connect for @connect_timeout seconds - begin - @socket.connect_nonblock(@socket_address) - rescue Errno::EINPROGRESS - # Block until there is a response or error - resp = IO.select([@socket], [@socket], [@socket], @connect_timeout) - if resp.nil? - raise ConnectionTimeoutError - end - end - - # If there was a failure this will raise an Error - begin - @socket.connect_nonblock(@socket_address) - rescue Errno::EISCONN - # Successfully connected - end + @socket.connect(@socket_address) end end