Class: HTTP::Timeout::Global
- Inherits:
-
PerOperation
- Object
- Null
- PerOperation
- HTTP::Timeout::Global
- Defined in:
- lib/http/timeout/global.rb
Constant Summary
Constants inherited from PerOperation
PerOperation::CONNECT_TIMEOUT, PerOperation::READ_TIMEOUT, PerOperation::WRITE_TIMEOUT
Instance Attribute Summary collapse
-
#time_left ⇒ Object
readonly
Returns the value of attribute time_left.
-
#total_timeout ⇒ Object
readonly
Returns the value of attribute total_timeout.
Attributes inherited from PerOperation
#connect_timeout, #read_timeout, #write_timeout
Attributes inherited from Null
Instance Method Summary collapse
- #connect(socket_class, host, port) ⇒ Object
- #connect_ssl ⇒ Object
-
#initialize(*args) ⇒ Global
constructor
A new instance of Global.
-
#readpartial(size) ⇒ Object
Read from the socket.
- #reset_counter ⇒ Object
-
#write(data) ⇒ Object
(also: #<<)
Write to the socket.
Methods inherited from Null
Constructor Details
#initialize(*args) ⇒ Global
Returns a new instance of Global.
6 7 8 9 10 |
# File 'lib/http/timeout/global.rb', line 6 def initialize(*args) super reset_counter end |
Instance Attribute Details
#time_left ⇒ Object (readonly)
Returns the value of attribute time_left.
4 5 6 |
# File 'lib/http/timeout/global.rb', line 4 def time_left @time_left end |
#total_timeout ⇒ Object (readonly)
Returns the value of attribute total_timeout.
4 5 6 |
# File 'lib/http/timeout/global.rb', line 4 def total_timeout @total_timeout end |
Instance Method Details
#connect(socket_class, host, port) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/http/timeout/global.rb', line 16 def connect(socket_class, host, port) reset_timer ::Timeout.timeout(time_left, TimeoutError) do @socket = socket_class.open(host, port) end log_time end |
#connect_ssl ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/http/timeout/global.rb', line 25 def connect_ssl reset_timer begin socket.connect_nonblock rescue IO::WaitReadable IO.select([socket], nil, nil, time_left) log_time retry rescue IO::WaitWritable IO.select(nil, [socket], nil, time_left) log_time retry end end |
#readpartial(size) ⇒ Object
Read from the socket
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/http/timeout/global.rb', line 42 def readpartial(size) reset_timer begin socket.read_nonblock(size) rescue IO::WaitReadable IO.select([socket], nil, nil, time_left) log_time retry end end |
#reset_counter ⇒ Object
12 13 14 |
# File 'lib/http/timeout/global.rb', line 12 def reset_counter @time_left = @total_timeout = connect_timeout + read_timeout + write_timeout end |
#write(data) ⇒ Object Also known as: <<
Write to the socket
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/http/timeout/global.rb', line 55 def write(data) reset_timer begin socket << data rescue IO::WaitWritable IO.select(nil, [socket], nil, time_left) log_time retry end end |