summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/socket/lib/socket.rb13
2 files changed, 10 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index ed3981829d..8a3d0bb8da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Apr 21 05:31:00 2015 Eric Wong <e@80x24.org>
+
+ * ext/socket/lib/socket.rb (connect_internal): avoid common exceptions
+ from connect_nonblock. [ruby-core:68909]
+
Mon Apr 20 23:46:53 2015 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_wreadlink): follow the official format of
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