summaryrefslogtreecommitdiff
path: root/ext/socket/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/lib')
-rw-r--r--ext/socket/lib/socket.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 2cd7aeadf9..2723f7b78c 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -50,17 +50,14 @@ class Addrinfo
sock.ipv6only! if self.ipv6?
sock.bind local_addrinfo if local_addrinfo
if timeout
- begin
- sock.connect_nonblock(self)
- rescue IO::WaitWritable
+ case sock.connect_nonblock(self, exception: false)
+ when 0 # success or EISCONN, other errors raise
+ break
+ when :wait_writable
if !IO.select(nil, [sock], nil, timeout)
raise Errno::ETIMEDOUT, 'user specified timeout'
end
- begin
- sock.connect_nonblock(self) # check connection failure
- rescue Errno::EISCONN
- end
- end
+ end while true
else
sock.connect(self)
end