From 641fe29855bae159338b0ab978472ef3f77eee5c Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 2 Dec 2008 06:34:19 +0000 Subject: * lib/net/protocol.rb (Net::BufferedIO#rbuf_fill): use read_nonblock instead of sysread wrapped by timeout to boost performance. a patch from Aaron Patterson in [ruby-core:20191]. fix #806 git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@20443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/protocol.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 0d489cdbc..3f6f416ba 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -131,9 +131,15 @@ module Net # :nodoc: BUFSIZE = 1024 * 16 def rbuf_fill - timeout(@read_timeout) { - @rbuf << @io.sysread(BUFSIZE) - } + begin + @rbuf << @io.read_nonblock(BUFSIZE) + rescue Errno::EWOULDBLOCK + if IO.select([@io], nil, nil, @read_timeout) + @rbuf << @io.read_nonblock(BUFSIZE) + else + raise Timeout::TimeoutError + end + end end def rbuf_consume(len) -- cgit