class HTTPX::Resolver::Native

  1. lib/httpx/resolver/native.rb
Superclass: Resolver

Implements a pure ruby name resolver, which abides by the Selectable API. It delegates DNS payload encoding/decoding to the resolv stlid gem.

Constants

DEFAULTS = { nameserver: nil, **Resolv::DNS::Config.default_config_hash, packet_size: 512, timeouts: Resolver::RESOLVE_TIMEOUT, }.freeze  
DNS_PORT = 53  

Attributes

state [R]

Public Class methods

new(family, options)
[show source]
   # File lib/httpx/resolver/native.rb
27 def initialize(family, options)
28   super
29   @ns_index = 0
30   @resolver_options = DEFAULTS.merge(@options.resolver_options)
31   @socket_type = @resolver_options.fetch(:socket_type, :udp)
32   @nameserver = if (nameserver = @resolver_options[:nameserver])
33     nameserver = nameserver[family] if nameserver.is_a?(Hash)
34     Array(nameserver)
35   end
36   @ndots = @resolver_options.fetch(:ndots, 1)
37   @search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) }
38   @_timeouts = Array(@resolver_options[:timeouts])
39   @timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup }
40   @name = nil
41   @queries = {}
42   @read_buffer = "".b
43   @write_buffer = Buffer.new(@resolver_options[:packet_size])
44   @state = :idle
45   @timer = nil
46 end

Public Instance methods

<<(connection)
[show source]
   # File lib/httpx/resolver/native.rb
83 def <<(connection)
84   if @nameserver.nil?
85     ex = ResolveError.new("No available nameserver")
86     ex.set_backtrace(caller)
87     connection.force_reset
88     throw(:resolve_error, ex)
89   else
90     @connections << connection
91     resolve
92   end
93 end
call()
[show source]
   # File lib/httpx/resolver/native.rb
64 def call
65   case @state
66   when :open
67     consume
68   end
69 end
close()
[show source]
   # File lib/httpx/resolver/native.rb
48 def close
49   transition(:closed)
50 end
closed?()
[show source]
   # File lib/httpx/resolver/native.rb
56 def closed?
57   @state == :closed
58 end
handle_socket_timeout(interval)
[show source]
    # File lib/httpx/resolver/native.rb
103 def handle_socket_timeout(interval); end
interests()
[show source]
   # File lib/httpx/resolver/native.rb
71 def interests
72   case @state
73   when :idle
74     transition(:open)
75   when :closed
76     transition(:idle)
77     transition(:open)
78   end
79 
80   calculate_interests
81 end
terminate()
[show source]
   # File lib/httpx/resolver/native.rb
52 def terminate
53   emit(:close, self)
54 end
timeout()
[show source]
    # File lib/httpx/resolver/native.rb
 95 def timeout
 96   return if @connections.empty?
 97 
 98   @start_timeout = Utils.now
 99   hosts = @queries.keys
100   @timeouts.values_at(*hosts).reject(&:empty?).map(&:first).min
101 end
to_io()
[show source]
   # File lib/httpx/resolver/native.rb
60 def to_io
61   @io.to_io
62 end