Class: HTTPX::Connection
- Inherits:
-
Object
- Object
- HTTPX::Connection
- Defined in:
- lib/httpx/connection.rb
Instance Method Summary collapse
- #build_channel(uri, **options) ⇒ Object
- #close ⇒ 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 = Options.new() @timeout = .timeout @selector = Selector.new @channels = [] end |
Instance Method Details
#build_channel(uri, **options) ⇒ Object
37 38 39 40 41 |
# File 'lib/httpx/connection.rb', line 37 def build_channel(uri, **) channel = Channel.by(uri, @options.merge()) register_channel(channel) channel end |
#close ⇒ Object
28 29 30 31 |
# File 'lib/httpx/connection.rb', line 28 def close @channels.each(&:close) next_tick until @channels.empty? 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.
47 48 49 50 51 |
# File 'lib/httpx/connection.rb', line 47 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) channel.call end monitor.interests = channel.interests end end |
#reset ⇒ Object
33 34 35 |
# File 'lib/httpx/connection.rb', line 33 def reset @channels.each(&:reset) end |
#running? ⇒ Boolean
15 16 17 |
# File 'lib/httpx/connection.rb', line 15 def running? !@channels.empty? end |