From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] socket: avoid exceptions in wrapper code
Date: Tue, 17 Nov 2015 01:05:48 +0000 [thread overview]
Message-ID: <20151117010548.16652-1-e@80x24.org> (raw)
* 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
reply other threads:[~2015-11-17 1:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151117010548.16652-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).