Class: HTTPX::Resolver::Native
- Inherits:
-
Resolver
show all
- Extended by:
- Forwardable
- Includes:
- _ToIO
- Defined in:
- lib/httpx/resolver/native.rb,
sig/resolver/native.rbs
Overview
Implements a pure ruby name resolver, which abides by the Selectable API.
It delegates DNS payload encoding/decoding to the resolv stlid gem.
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, #early_resolve, #emit_addresses, #empty?, #inflight?, #initial_call, #lazy_resolve, multi?, #on_error
Methods included from Loggable
#log, #log_exception, log_identifiers
#inflight?, #initial_call, #on_error
Instance Attribute Details
#state ⇒ Symbol
Returns the value of attribute state.
26
27
28
|
# File 'lib/httpx/resolver/native.rb', line 26
def state
@state
end
|
Instance Method Details
#<<(connection) ⇒ void
This method returns an undefined value.
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/httpx/resolver/native.rb', line 105
def <<(connection)
if @nameserver.nil?
ex = ResolveError.new("No available nameserver")
ex.set_backtrace(caller)
connection.force_close
throw(:resolve_error, ex)
else
@connections << connection
resolve
end
end
|
#call ⇒ void
This method returns an undefined value.
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/httpx/resolver/native.rb', line 75
def call
case @state
when :idle, :closed
return if @connections.empty?
transition(:idle) if @state == :closed
transition(:open)
consume if @state == :open
when :open
consume
end
end
|
#close ⇒ Object
48
49
50
|
# File 'lib/httpx/resolver/native.rb', line 48
def close
transition(:closed)
end
|
#closed? ⇒ Boolean
67
68
69
|
# File 'lib/httpx/resolver/native.rb', line 67
def closed?
@state == :idle || @state == :closed
end
|
#closed_for_select? ⇒ Boolean
89
90
91
|
# File 'lib/httpx/resolver/native.rb', line 89
def closed_for_select?
@state == :closed
end
|
#force_close ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/httpx/resolver/native.rb', line 52
def force_close(*)
@timer.cancel if @timer
@timer = @name = @message_id = nil
@queries.clear
@timeouts.clear
close
super
ensure
terminate
end
|
#handle_error(error) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/httpx/resolver/native.rb', line 133
def handle_error(error)
if error.respond_to?(:connection) &&
error.respond_to?(:host)
reset_hostname(error.host, connection: error.connection)
else
@queries.each do |host, connection|
reset_hostname(host, connection: connection)
end
end
super
end
|
#handle_socket_timeout(interval) ⇒ void
This method returns an undefined value.
131
|
# File 'lib/httpx/resolver/native.rb', line 131
def handle_socket_timeout(interval); end
|
#interests ⇒ :r, ...
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/httpx/resolver/native.rb', line 93
def interests
case @state
when :idle
transition(:open)
when :closed
transition(:idle)
transition(:open)
end
calculate_interests
end
|
#on_io_error ⇒ void
This method returns an undefined value.
43
|
# File 'sig/resolver/native.rbs', line 43
def on_io_error: (IOError error) -> void
|
#terminate ⇒ Object
63
64
65
|
# File 'lib/httpx/resolver/native.rb', line 63
def terminate
disconnect
end
|
#timeout ⇒ interval?
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/httpx/resolver/native.rb', line 117
def timeout
return unless @name
@start_timeout = Utils.now
timeouts = @timeouts[@name]
return if timeouts.empty?
log(level: 2) { "resolver #{FAMILY_TYPES[@record_type]}: next timeout #{timeouts.first} secs... (#{timeouts.size - 1} left)" }
timeouts.first
end
|
#to_io ⇒ Object
71
72
73
|
# File 'lib/httpx/resolver/native.rb', line 71
def to_io
@io.to_io
end
|