summaryrefslogtreecommitdiff
path: root/lib/net/protocol.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-02 06:34:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-02 06:34:19 +0000
commit348d715eaa24989fffd02c3c073188d555969bb8 (patch)
tree4cd51b748905331b8278633c02f7f1918ef965b2 /lib/net/protocol.rb
parenta01e1cfb5b56b3a9e8509d9cf04f5bcfba7caceb (diff)
downloadruby-348d715eaa24989fffd02c3c073188d555969bb8.tar.gz
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@20443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/protocol.rb')
-rw-r--r--lib/net/protocol.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 0d489cdbc8..3f6f416bab 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)