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 end

Public Instance methods

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