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 ⇒ 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
38 39 40 41 42 |
# File 'lib/httpx/connection.rb', line 38 def build_channel(uri, **) channel = Channel.by(uri, @options.merge()) register_channel(channel) channel end |
#close ⇒ Object
33 34 35 36 |
# File 'lib/httpx/connection.rb', line 33 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.
48 49 50 51 52 |
# File 'lib/httpx/connection.rb', line 48 def find_channel(uri) @channels.find do |channel| channel.match?(uri) end end |
#next_tick ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 rescue TimeoutError => ex @channels.each do |ch| ch.emit(:error, ex) end end |
#running? ⇒ Boolean
15 16 17 |
# File 'lib/httpx/connection.rb', line 15 def running? !@channels.empty? end |