Method: HTTPX::TCP#initialize

Defined in:
lib/httpx/io/tcp.rb

#initialize(origin, addresses, options) ⇒ TCP

Returns a new instance of TCP.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/httpx/io/tcp.rb', line 15

def initialize(origin, addresses, options)
  @state = :idle
  @keep_open = false
  @addresses = []
  @ip_index = -1
  @ip = nil
  @hostname = origin.host
  @options = options
  @fallback_protocol = @options.fallback_protocol
  @port = origin.port
  @interests = :w
  if @options.io
    @io = case @options.io
          when Hash
            @options.io[origin.authority]
          else
            @options.io
    end
    raise Error, "Given IO objects do not match the request authority" unless @io

    _, _, _, ip = @io.addr
    @ip = Resolver::Entry.new(ip)
    @addresses << @ip
    @keep_open = true
    @state = :connected
  else
    add_addresses(addresses)
  end
  @ip_index = @addresses.size - 1
end