Net::ReadTimeout and Net::WriteTimeout should tell the cause socket
* lib/net/protocol.rb (ReadTimeout, WriteTimeout): Net::ReadTimeout and Net::WriteTimeout should tell the cause socket [Feature #14832] [ruby-core:87440] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2ea54f0c1d
commit
5f91caceea
@ -75,13 +75,39 @@ module Net # :nodoc:
|
|||||||
# ReadTimeout, a subclass of Timeout::Error, is raised if a chunk of the
|
# ReadTimeout, a subclass of Timeout::Error, is raised if a chunk of the
|
||||||
# response cannot be read within the read_timeout.
|
# response cannot be read within the read_timeout.
|
||||||
|
|
||||||
class ReadTimeout < Timeout::Error; end
|
class ReadTimeout < Timeout::Error
|
||||||
|
def initialize(io = nil)
|
||||||
|
@io = io
|
||||||
|
end
|
||||||
|
attr_reader :io
|
||||||
|
|
||||||
|
def message
|
||||||
|
msg = super
|
||||||
|
if @io
|
||||||
|
msg = "#{msg} with #{@io.inspect}"
|
||||||
|
end
|
||||||
|
msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# WriteTimeout, a subclass of Timeout::Error, is raised if a chunk of the
|
# WriteTimeout, a subclass of Timeout::Error, is raised if a chunk of the
|
||||||
# response cannot be written within the write_timeout. Not raised on Windows.
|
# response cannot be written within the write_timeout. Not raised on Windows.
|
||||||
|
|
||||||
class WriteTimeout < Timeout::Error; end
|
class WriteTimeout < Timeout::Error
|
||||||
|
def initialize(io = nil)
|
||||||
|
@io = io
|
||||||
|
end
|
||||||
|
attr_reader :io
|
||||||
|
|
||||||
|
def message
|
||||||
|
msg = super
|
||||||
|
if @io
|
||||||
|
msg = "#{msg} with #{@io.inspect}"
|
||||||
|
end
|
||||||
|
msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
class BufferedIO #:nodoc: internal use only
|
class BufferedIO #:nodoc: internal use only
|
||||||
@ -188,12 +214,12 @@ module Net # :nodoc:
|
|||||||
rv.clear
|
rv.clear
|
||||||
return
|
return
|
||||||
when :wait_readable
|
when :wait_readable
|
||||||
@io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout
|
(io = @io.to_io).wait_readable(@read_timeout) or raise Net::ReadTimeout.new(io)
|
||||||
# continue looping
|
# continue looping
|
||||||
when :wait_writable
|
when :wait_writable
|
||||||
# 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
|
||||||
@io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
|
(io = @io.to_io).wait_writable(@read_timeout) or raise Net::ReadTimeout.new(io)
|
||||||
# continue looping
|
# continue looping
|
||||||
when nil
|
when nil
|
||||||
raise EOFError, 'end of file reached'
|
raise EOFError, 'end of file reached'
|
||||||
@ -267,7 +293,7 @@ module Net # :nodoc:
|
|||||||
end
|
end
|
||||||
# continue looping
|
# continue looping
|
||||||
when :wait_writable
|
when :wait_writable
|
||||||
@io.to_io.wait_writable(@write_timeout) or raise Net::WriteTimeout
|
(io = @io.to_io).wait_writable(@write_timeout) or raise Net::WriteTimeout.new(io)
|
||||||
# continue looping
|
# continue looping
|
||||||
end while need_retry
|
end while need_retry
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user