lib/net/protocol.rb (rbuf_fill): avoid exception with read_nonblock

Exceptions are noisy in debug output and waste allocations.
Use "exception: false" introduced in 2.1 to return symbols for
common errors instead.

Follow-up commits will be prepared to reduce EOFError exceptions
to further quiet debug output and IO.select may be replaced by
io/wait methods if available to reduce allocations.

[ruby-core:68787] [Feature #11044]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-04-10 21:05:29 +00:00
parent 9e459f7aa9
commit db2ff03bc0
2 changed files with 18 additions and 15 deletions

View File

@ -1,3 +1,8 @@
Sat Apr 11 04:46:42 2015 Eric Wong <e@80x24.org>
* lib/net/protocol.rb (rbuf_fill): avoid exception with read_nonblock
[ruby-core:68787] [Feature #11044]
Fri Apr 10 23:57:44 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Apr 10 23:57:44 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (need_normalization): use getattrlist() if fgetattrlist() * dir.c (need_normalization): use getattrlist() if fgetattrlist()

View File

@ -149,23 +149,21 @@ module Net # :nodoc:
BUFSIZE = 1024 * 16 BUFSIZE = 1024 * 16
def rbuf_fill def rbuf_fill
begin case rv = @io.read_nonblock(BUFSIZE, exception: false)
@rbuf << @io.read_nonblock(BUFSIZE) when String
rescue IO::WaitReadable return @rbuf << rv
if IO.select([@io], nil, nil, @read_timeout) when :wait_readable
retry IO.select([@io], nil, nil, @read_timeout) or raise Net::ReadTimeout
else # continue looping
raise Net::ReadTimeout when :wait_writable
end
rescue IO::WaitWritable
# OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable. # OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
# http://www.openssl.org/support/faq.html#PROG10 # http://www.openssl.org/support/faq.html#PROG10
if IO.select(nil, [@io], nil, @read_timeout) IO.select(nil, [@io], nil, @read_timeout) or raise Net::ReadTimeout
retry # continue looping
else when nil
raise Net::ReadTimeout # callers do not care about backtrace, so avoid allocating for it
end raise EOFError, 'end of file reached', []
end end while true
end end
def rbuf_consume(len) def rbuf_consume(len)