Class: HTTPX::Connection
- Inherits:
-
Object
- Object
- HTTPX::Connection
- Defined in:
- lib/httpx/connection.rb
Instance Method Summary collapse
- #build_channel(uri, **options) ⇒ Object
- #close(channel = nil) ⇒ Object
-
#find_channel(uri) ⇒ Object
opens a channel to the IP reachable through
uri. -
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #next_tick(timeout: @timeout.timeout) ⇒ Object
- #reset ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 |
# File 'lib/httpx/connection.rb', line 8 def initialize() = Options.new() @timeout = .timeout @selector = Selector.new @channels = [] end |
Instance Method Details
#build_channel(uri, **options) ⇒ Object
41 42 43 44 45 |
# File 'lib/httpx/connection.rb', line 41 def build_channel(uri, **) channel = Channel.by(uri, .merge()) register_channel(channel) channel end |
#close(channel = nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/httpx/connection.rb', line 28 def close(channel = nil) if channel channel.close else @channels.each(&:close) next_tick until @selector.empty? end end |
#find_channel(uri) ⇒ Object
opens a channel to the IP reachable through uri. Many hostnames are reachable through the same IP, so we try to maximize pipelining by opening as few channels as possible.
51 52 53 54 55 |
# File 'lib/httpx/connection.rb', line 51 def find_channel(uri) @channels.find do |channel| channel.match?(uri) end end |
#next_tick(timeout: @timeout.timeout) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/httpx/connection.rb', line 19 def next_tick(timeout: @timeout.timeout) @selector.select(timeout) do |monitor| if (channel = monitor.value) consume(channel) end monitor.interests = channel.interests end end |
#reset ⇒ Object
37 38 39 |
# File 'lib/httpx/connection.rb', line 37 def reset @channels.each(&:reset) end |
#running? ⇒ Boolean
15 16 17 |
# File 'lib/httpx/connection.rb', line 15 def running? !@channels.empty? end |