dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] socket: avoid exceptions in wrapper code
@ 2015-11-17  1:05 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-11-17  1:05 UTC (permalink / raw)
  To: spew

* ext/socket/lib/socket.rb (Socket.accept_loop): avoid exceptions
  (Socket.udp_server_recv): ditto

Exceptions make debug output noisy and allocations+backtrace
generation hurt performance
---
 ext/socket/lib/socket.rb | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index bc3d38a..14f51fa 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -790,11 +790,8 @@ def self.accept_loop(*sockets) # :yield: socket, client_addrinfo
     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
       }
     }
@@ -958,11 +955,8 @@ def self.udp_server_sockets(host=nil, port)
   #
   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)
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-17  1:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17  1:05 [PATCH] socket: avoid exceptions in wrapper code Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).