summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-17 01:16:25 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-17 01:16:25 +0000
commit8478b30267c09152f1be6f55967fa3444e878ea4 (patch)
tree4af4b42eeb59efa3eb3fc66af22c732ae5821e84 /ext
parenteda2441b5354829bea9225a99e0b96f0ba40b7ab (diff)
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
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/lib/socket.rb14
1 files changed, 4 insertions, 10 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 705a0b8..c9929ae 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -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)