From 46acbe9ddd628b378b0d711fefc7f9e0a68aa616 Mon Sep 17 00:00:00 2001 From: normal Date: Mon, 20 Apr 2015 20:46:08 +0000 Subject: socket: avoid common exceptions when calling connect_nonblock Errno::EISCONN and IO::WaitReadable exceptions are common, expensive, and noisy under normal use. Avoid raising on them since they are not exceptional. * ext/socket/lib/socket.rb (connect_internal): avoid common exceptions from connect_nonblock. [ruby-core:68909] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/lib/socket.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'ext') 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 -- cgit v1.2.3