ruby-changes:40523
From: normal <ko1@a...>
Date: Tue, 17 Nov 2015 10:16:47 +0900 (JST)
Subject: [ruby-changes:40523] normal:r52604 (trunk): socket: avoid exceptions in wrapper code
normal 2015-11-17 10:16:25 +0900 (Tue, 17 Nov 2015) New Revision: 52604 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52604 Log: socket: avoid exceptions in wrapper code * ext/socket/lib/socket.rb (Socket.accept_loop): avoid exceptions (Socket.udp_server_recv): ditto Exceptions for common "errors" make debug output noisy and allocations+backtrace generation hurt performance. [ruby-core:66385] [ruby-core:69473] Modified files: trunk/ChangeLog trunk/ext/socket/lib/socket.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 52603) +++ ChangeLog (revision 52604) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Nov 17 10:12:30 2015 Eric Wong <e@8...> + + * ext/socket/lib/socket.rb (Socket.accept_loop): avoid exceptions + (Socket.udp_server_recv): ditto + Tue Nov 17 09:59:00 2015 Eric Wong <e@8...> * ext/socket/ancdata.c (bsock_sendmsg_internal): avoid arg parsing Index: ext/socket/lib/socket.rb =================================================================== --- ext/socket/lib/socket.rb (revision 52603) +++ ext/socket/lib/socket.rb (revision 52604) @@ -792,11 +792,8 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L792 loop { readable, _, _ = IO.select(sockets) readable.each {|r| - begin - sock, addr = r.accept_nonblock - rescue IO::WaitReadable - next - end + sock, addr = r.accept_nonblock(exception: false) + next if sock == :wait_readable yield sock, addr } } @@ -960,11 +957,8 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ext/socket/lib/socket.rb#L957 # def self.udp_server_recv(sockets) sockets.each {|r| - begin - msg, sender_addrinfo, _, *controls = r.recvmsg_nonblock - rescue IO::WaitReadable - next - end + msg, sender_addrinfo, _, *controls = r.recvmsg_nonblock(exception: false) + next if msg == :wait_readable ai = r.local_address if ai.ipv6? and pktinfo = controls.find {|c| c.cmsg_is?(:IPV6, :PKTINFO) } ai = Addrinfo.udp(pktinfo.ipv6_pktinfo_addr.ip_address, ai.ip_port) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/