Class: HTTPX::Resolver::Native
- Inherits:
-
Resolver
show all
- Extended by:
- Forwardable
- Defined in:
- lib/httpx/resolver/native.rb
Constant Summary
collapse
- DEFAULTS =
{
nameserver: nil,
**Resolv::DNS::Config.default_config_hash,
packet_size: 512,
timeouts: Resolver::RESOLVE_TIMEOUT,
}.freeze
- DNS_PORT =
53
Constants inherited
from Resolver
Resolver::FAMILY_TYPES, Resolver::RECORD_TYPES
Constants included
from Loggable
Loggable::COLORS, Loggable::USE_DEBUG_LOG
Instance Attribute Summary collapse
Attributes inherited from Resolver
#current_selector, #current_session, #family, #multi, #options
Instance Method Summary
collapse
Methods inherited from Resolver
#each_connection, #emit_addresses, #empty?, #inflight?, multi?
Methods included from Loggable
#log, #log_exception
Methods included from Callbacks
#callbacks_for?, #emit, #on, #once
Constructor Details
#initialize(family, options) ⇒ Native
Returns a new instance of Native.
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/httpx/resolver/native.rb', line 24
def initialize(family, options)
super
@ns_index = 0
@resolver_options = DEFAULTS.merge(@options.resolver_options)
@socket_type = @resolver_options.fetch(:socket_type, :udp)
@nameserver = if (nameserver = @resolver_options[:nameserver])
nameserver = nameserver[family] if nameserver.is_a?(Hash)
Array(nameserver)
end
@ndots = @resolver_options.fetch(:ndots, 1)
@search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) }
@_timeouts = Array(@resolver_options[:timeouts])
@timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup }
@connections = []
@queries = {}
@read_buffer = "".b
@write_buffer = Buffer.new(@resolver_options[:packet_size])
@state = :idle
end
|
Instance Attribute Details
#state ⇒ Object
Returns the value of attribute state.
22
23
24
|
# File 'lib/httpx/resolver/native.rb', line 22
def state
@state
end
|
Instance Method Details
#<<(connection) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/httpx/resolver/native.rb', line 88
def <<(connection)
if @nameserver.nil?
ex = ResolveError.new("No available nameserver")
ex.set_backtrace(caller)
connection.force_reset
throw(:resolve_error, ex)
else
@connections << connection
resolve
end
end
|
#call ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/httpx/resolver/native.rb', line 56
def call
case @state
when :open
consume
end
nil
rescue Errno::EHOSTUNREACH => e
@ns_index += 1
nameserver = @nameserver
if nameserver && @ns_index < nameserver.size
log { "resolver: failed resolving on nameserver #{@nameserver[@ns_index - 1]} (#{e.message})" }
transition(:idle)
@timeouts.clear
else
handle_error(e)
end
rescue NativeResolveError => e
handle_error(e)
end
|
#close ⇒ Object
44
45
46
|
# File 'lib/httpx/resolver/native.rb', line 44
def close
transition(:closed)
end
|
#closed? ⇒ Boolean
48
49
50
|
# File 'lib/httpx/resolver/native.rb', line 48
def closed?
@state == :closed
end
|
#handle_socket_timeout(interval) ⇒ Object
108
109
110
|
# File 'lib/httpx/resolver/native.rb', line 108
def handle_socket_timeout(interval)
do_retry(interval)
end
|
#interests ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/httpx/resolver/native.rb', line 76
def interests
case @state
when :idle
transition(:open)
when :closed
transition(:idle)
transition(:open)
end
calculate_interests
end
|
#timeout ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/httpx/resolver/native.rb', line 100
def timeout
return if @connections.empty?
@start_timeout = Utils.now
hosts = @queries.keys
@timeouts.values_at(*hosts).reject(&:empty?).map(&:first).min
end
|
#to_io ⇒ Object
52
53
54
|
# File 'lib/httpx/resolver/native.rb', line 52
def to_io
@io.to_io
end
|