Project

General

Profile

Feature #14832 ยป timeout.patch

usa (Usaku NAKAMURA), 06/07/2018 10:49 AM

View differences:

lib/net/protocol.rb (working copy)
75 75
  # ReadTimeout, a subclass of Timeout::Error, is raised if a chunk of the
76 76
  # response cannot be read within the read_timeout.
77 77

  
78
  class ReadTimeout            < Timeout::Error; end
78
  class ReadTimeout < Timeout::Error
79
    def initialize(io = nil)
80
      @io = io
81
      @io_inspect = @io.inspect
82
    end
83
    attr_reader :io
79 84

  
85
    def message
86
      msg = super
87
      if @io_inspect
88
        msg = "#{msg} with #{@io_inspect}"
89
      end
90
      msg
91
    end
92
  end
93

  
80 94
  ##
81 95
  # WriteTimeout, a subclass of Timeout::Error, is raised if a chunk of the
82 96
  # response cannot be read within the read_timeout.
83 97

  
84
  class WriteTimeout            < Timeout::Error; end
98
  class WriteTimeout < Timeout::Error
99
    def initialize(io = nil)
100
      @io = io
101
      @io_inspect = @io.inspect
102
    end
103
    attr_reader :io
85 104

  
105
    def message
106
      msg = super
107
      if @io_inspect
108
        msg = "#{msg} with #{@io_inspect}"
109
      end
110
      msg
111
    end
112
  end
86 113

  
114

  
87 115
  class BufferedIO   #:nodoc: internal use only
88 116
    def initialize(io, read_timeout: 60, write_timeout: 60, continue_timeout: nil, debug_output: nil)
89 117
      @io = io
......
188 216
        rv.clear
189 217
        return
190 218
      when :wait_readable
191
        @io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout
219
        (io = @io.to_io).wait_readable(@read_timeout) or raise Net::ReadTimeout.new(io)
192 220
        # continue looping
193 221
      when :wait_writable
194 222
        # OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
195 223
        # http://www.openssl.org/support/faq.html#PROG10
196
        @io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
224
        (io = @io.to_io).wait_writable(@read_timeout) or raise Net::ReadTimeout.new(io)
197 225
        # continue looping
198 226
      when nil
199 227
        raise EOFError, 'end of file reached'
......
267 295
          end
268 296
          # continue looping
269 297
        when :wait_writable
270
          @io.to_io.wait_writable(@write_timeout) or raise Net::WriteTimeout
298
          (io = @io.to_io).wait_writable(@write_timeout) or raise Net::WriteTimeout.new(io)
271 299
          # continue looping
272 300
        end while need_retry
273 301
      end