Class: HTTP::Timeout::PerOperation
- Defined in:
- lib/http/timeout/per_operation.rb
Direct Known Subclasses
Constant Summary collapse
- CONNECT_TIMEOUT =
0.25- WRITE_TIMEOUT =
0.25- READ_TIMEOUT =
0.25
Instance Attribute Summary collapse
-
#connect_timeout ⇒ Object
readonly
Returns the value of attribute connect_timeout.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#write_timeout ⇒ Object
readonly
Returns the value of attribute write_timeout.
Attributes inherited from Null
Instance Method Summary collapse
- #connect(socket_class, host, port, nodelay = false) ⇒ Object
- #connect_ssl ⇒ Object
-
#initialize(*args) ⇒ PerOperation
constructor
A new instance of PerOperation.
-
#readpartial(size) ⇒ Object
Read data from the socket.
-
#write(data) ⇒ Object
Write data to the socket.
Methods inherited from Null
Constructor Details
#initialize(*args) ⇒ PerOperation
Returns a new instance of PerOperation.
16 17 18 19 20 21 22 |
# File 'lib/http/timeout/per_operation.rb', line 16 def initialize(*args) super @read_timeout = .fetch(:read_timeout, READ_TIMEOUT) @write_timeout = .fetch(:write_timeout, WRITE_TIMEOUT) @connect_timeout = .fetch(:connect_timeout, CONNECT_TIMEOUT) end |
Instance Attribute Details
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
14 15 16 |
# File 'lib/http/timeout/per_operation.rb', line 14 def connect_timeout @connect_timeout end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
14 15 16 |
# File 'lib/http/timeout/per_operation.rb', line 14 def read_timeout @read_timeout end |
#write_timeout ⇒ Object (readonly)
Returns the value of attribute write_timeout.
14 15 16 |
# File 'lib/http/timeout/per_operation.rb', line 14 def write_timeout @write_timeout end |
Instance Method Details
#connect(socket_class, host, port, nodelay = false) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/http/timeout/per_operation.rb', line 24 def connect(socket_class, host, port, nodelay = false) ::Timeout.timeout(connect_timeout, TimeoutError) do @socket = socket_class.open(host, port) @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay end end |
#connect_ssl ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/http/timeout/per_operation.rb', line 31 def connect_ssl rescue_readable(@connect_timeout) do rescue_writable(@connect_timeout) do @socket.connect_nonblock end end end |
#readpartial(size) ⇒ Object
Read data from the socket
42 43 44 45 46 47 48 |
# File 'lib/http/timeout/per_operation.rb', line 42 def readpartial(size) rescue_readable do @socket.read_nonblock(size) end rescue EOFError :eof end |
#write(data) ⇒ Object
Write data to the socket
51 52 53 54 55 56 57 |
# File 'lib/http/timeout/per_operation.rb', line 51 def write(data) rescue_writable do @socket.write_nonblock(data) end rescue EOFError :eof end |