ruby-changes:38282
From: normal <ko1@a...>
Date: Tue, 21 Apr 2015 05:46:21 +0900 (JST)
Subject: [ruby-changes:38282] normal:r50363 (trunk): socket: avoid common exceptions when calling connect_nonblock
normal 2015-04-21 05:46:08 +0900 (Tue, 21 Apr 2015) New Revision: 50363 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50363 Log: 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] Modified files: trunk/ChangeLog trunk/ext/socket/lib/socket.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 50362) +++ ChangeLog (revision 50363) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Apr 21 05:31:00 2015 Eric Wong <e@8...> + + * 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@r...> * win32/win32.c (rb_w32_wreadlink): follow the official format of Index: ext/socket/lib/socket.rb =================================================================== --- ext/socket/lib/socket.rb (revision 50362) +++ ext/socket/lib/socket.rb (revision 50363) @@ -50,17 +50,14 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L50 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/