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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-11-17 01:16:25 +00:00
Родитель eda2441b53
Коммит 8478b30267
2 изменённых файлов: 9 добавлений и 10 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Nov 17 10:12:30 2015 Eric Wong <e@80x24.org>
* 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@80x24.org>
* ext/socket/ancdata.c (bsock_sendmsg_internal): avoid arg parsing

Просмотреть файл

@ -792,11 +792,8 @@ class Socket < BasicSocket
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
#
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)