celluloid / celluloid-io

UNMAINTAINED: See celluloid/celluloid#779 - Evented sockets for Celluloid actors
https://celluloid.io
MIT License
879 stars 93 forks source link

TCPSocket connect_nonblock sometimes not working. #138

Closed ioquatix closed 9 years ago

ioquatix commented 9 years ago

https://github.com/celluloid/celluloid/issues/436#issuecomment-91058400

Proposed fix:

    begin
      @socket.connect_nonblock Socket.sockaddr_in(remote_port, @addr.to_s)
    rescue Errno::EINPROGRESS, Errno::EALREADY
      wait_writable

      # HAX: for some reason we need to finish_connect ourselves on JRuby
      # This logic is unnecessary but JRuby still throws Errno::EINPROGRESS
      # if we retry the non-blocking connect instead of just finishing it
      retry unless defined?(JRUBY_VERSION) && @socket.to_channel.finish_connect
    rescue Errno::EISCONN
      # We're now connected! Yay exceptions for flow control
      # NOTE: This is the approach the Ruby stdlib docs suggest ;_;
    end