From: Jeremy Kemper Date: 2009-02-07T13:27:55+09:00 Subject: [ruby-core:21905] [Bug #806] Net::Protocol#rbuf_fill is slow Issue #806 has been updated by Jeremy Kemper. Breaks if the IO doesn't respond to read_nonblock. StringIO, for example. Fall back to sysread in that case: Index: lib/net/protocol.rb =================================================================== --- lib/net/protocol.rb (revision 22024) +++ lib/net/protocol.rb (working copy) @@ -131,14 +131,20 @@ BUFSIZE = 1024 * 16 def rbuf_fill - begin - @rbuf << @io.read_nonblock(BUFSIZE) - rescue Errno::EWOULDBLOCK - if IO.select([@io], nil, nil, @read_timeout) - retry - else - raise Timeout::TimeoutError + if @io.respond_to?(:read_nonblock) + begin + @rbuf << @io.read_nonblock(BUFSIZE) + rescue Errno::EWOULDBLOCK + if IO.select([@io], nil, nil, @read_timeout) + retry + else + raise Timeout::TimeoutError + end end + else + timeout(@read_timeout) do + @rbuf << @io.sysread(BUFSIZE) + end end end ---------------------------------------- http://redmine.ruby-lang.org/issues/show/806 ---------------------------------------- http://redmine.ruby-lang.org