Project

General

Profile

Feature #6088 » net.protocol.read_timeout.patch

drbrain (Eric Hodel), 02/26/2012 07:14 AM

View differences:

lib/net/protocol.rb (working copy)
class ProtoCommandError < ProtocolError; end
class ProtoRetriableError < ProtocolError; end
ProtocRetryError = ProtoRetriableError
class ReadTimeout < Timeout::Error; end
class BufferedIO #:nodoc: internal use only
......
if IO.select([@io], nil, nil, @read_timeout)
retry
else
raise Timeout::Error
raise Net::ReadTimeout
end
rescue IO::WaitWritable
# OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
......
if IO.select(nil, [@io], nil, @read_timeout)
retry
else
raise Timeout::Error
raise Net::ReadTimeout
end
end
end
test/net/http/test_http.rb (working copy)
port = server.addr[1]
conn = Net::HTTP.new('localhost', port)
conn.read_timeout = 1
conn.open_timeout = 1
conn.read_timeout = 0.001
conn.open_timeout = 0.001
th = Thread.new do
assert_raise(Timeout::Error) {
assert_raise(Net::ReadTimeout) {
conn.get('/')
}
end
(1-1/3)