ruby-changes:54087
From: usa <ko1@a...>
Date: Mon, 10 Dec 2018 16:11:22 +0900 (JST)
Subject: [ruby-changes:54087] usa:r66308 (trunk): Net::ReadTimeout and Net::WriteTimeout should tell the cause socket
usa 2018-12-10 16:11:18 +0900 (Mon, 10 Dec 2018) New Revision: 66308 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66308 Log: 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] Modified files: trunk/lib/net/protocol.rb Index: lib/net/protocol.rb =================================================================== --- lib/net/protocol.rb (revision 66307) +++ lib/net/protocol.rb (revision 66308) @@ -75,13 +75,39 @@ module Net # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/protocol.rb#L75 # ReadTimeout, a subclass of Timeout::Error, is raised if a chunk of the # 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 # 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 @@ -188,12 +214,12 @@ module Net # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/protocol.rb#L214 rv.clear return 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 when :wait_writable # OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable. # 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 when nil raise EOFError, 'end of file reached' @@ -267,7 +293,7 @@ module Net # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/protocol.rb#L293 end # continue looping 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 end while need_retry end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/