Class: HTTPX::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/connection.rb

Instance Method Summary collapse

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 = Options.new(options)
  @timeout = options.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, **options)
  channel = Channel.by(uri, @options.merge(options))
  register_channel(channel)
  channel
end

#closeObject



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_tickObject



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

Returns:

  • (Boolean)


15
16
17
# File 'lib/httpx/connection.rb', line 15

def running?
  !@channels.empty?
end