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, nodelay = false) ⇒ Object
- #connect_ssl ⇒ Object
-
#initialize(*args) ⇒ Global
constructor
A new instance of Global.
-
#readpartial(size) ⇒ Object
Read from the socket.
-
#reset_counter ⇒ Object
To future me: Don't remove this again, past you was smarter.
-
#write(data) ⇒ Object
(also: #<<)
Write to the socket.
Methods inherited from Null
Constructor Details
#initialize(*args) ⇒ Global
Returns a new instance of Global.
11 12 13 14 |
# File 'lib/http/timeout/global.rb', line 11 def initialize(*args) super reset_counter end |
Instance Attribute Details
#time_left ⇒ Object (readonly)
Returns the value of attribute time_left.
9 10 11 |
# File 'lib/http/timeout/global.rb', line 9 def time_left @time_left end |
#total_timeout ⇒ Object (readonly)
Returns the value of attribute total_timeout.
9 10 11 |
# File 'lib/http/timeout/global.rb', line 9 def total_timeout @total_timeout end |
Instance Method Details
#connect(socket_class, host, port, nodelay = false) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/http/timeout/global.rb', line 22 def connect(socket_class, host, port, nodelay = false) reset_timer ::Timeout.timeout(time_left, TimeoutError) do @socket = socket_class.open(host, port) @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay end log_time end |
#connect_ssl ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/http/timeout/global.rb', line 32 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
49 50 51 |
# File 'lib/http/timeout/global.rb', line 49 def readpartial(size) perform_io { read_nonblock(size) } end |
#reset_counter ⇒ Object
To future me: Don't remove this again, past you was smarter.
17 18 19 20 |
# File 'lib/http/timeout/global.rb', line 17 def reset_counter @time_left = connect_timeout + read_timeout + write_timeout @total_timeout = time_left end |
#write(data) ⇒ Object Also known as: <<
Write to the socket
54 55 56 |
# File 'lib/http/timeout/global.rb', line 54 def write(data) perform_io { write_nonblock(data) } end |