Skip to content

Commit

Permalink
socket: avoid exceptions in wrapper code
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
normal committed Nov 17, 2015
1 parent eda2441 commit 8478b30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 4 additions & 10 deletions ext/socket/lib/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,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
}
}
Expand Down Expand Up @@ -960,11 +957,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)
Expand Down

0 comments on commit 8478b30

Please sign in to comment.