Class: HTTPX::Resolver::Native
- Extended by:
- Forwardable
- Defined in:
- lib/httpx/resolver/native.rb
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
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Attributes inherited from Resolver
#current_selector, #current_session, #family, #multi, #options
Instance Method Summary collapse
- #<<(connection) ⇒ Object
- #call ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #handle_socket_timeout(interval) ⇒ Object
-
#initialize(family, options) ⇒ Native
constructor
A new instance of Native.
- #interests ⇒ Object
- #terminate ⇒ Object
- #timeout ⇒ Object
- #to_io ⇒ Object
Methods inherited from Resolver
#each_connection, #emit_addresses, #empty?, #inflight?, multi?
Methods included from Loggable
#log, #log_exception, #log_redact
Methods included from Callbacks
#callbacks_for?, #emit, #on, #once
Constructor Details
#initialize(family, options) ⇒ Native
Returns a new instance of Native.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/httpx/resolver/native.rb', line 27 def initialize(family, ) super @ns_index = 0 = DEFAULTS.merge(.) @socket_type = .fetch(:socket_type, :udp) @nameserver = if (nameserver = [:nameserver]) nameserver = nameserver[family] if nameserver.is_a?(Hash) Array(nameserver) end @ndots = .fetch(:ndots, 1) @search = Array([:search]).map { |srch| srch.scan(/[^.]+/) } @_timeouts = Array([:timeouts]) @timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup } @name = nil @queries = {} @read_buffer = "".b @write_buffer = Buffer.new([:packet_size]) @state = :idle end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
25 26 27 |
# File 'lib/httpx/resolver/native.rb', line 25 def state @state end |
Instance Method Details
#<<(connection) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/httpx/resolver/native.rb', line 82 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
63 64 65 66 67 68 |
# File 'lib/httpx/resolver/native.rb', line 63 def call case @state when :open consume end end |
#close ⇒ Object
47 48 49 |
# File 'lib/httpx/resolver/native.rb', line 47 def close transition(:closed) end |
#closed? ⇒ Boolean
55 56 57 |
# File 'lib/httpx/resolver/native.rb', line 55 def closed? @state == :closed end |
#handle_socket_timeout(interval) ⇒ Object
102 |
# File 'lib/httpx/resolver/native.rb', line 102 def handle_socket_timeout(interval); end |
#interests ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/httpx/resolver/native.rb', line 70 def interests case @state when :idle transition(:open) when :closed transition(:idle) transition(:open) end calculate_interests end |
#terminate ⇒ Object
51 52 53 |
# File 'lib/httpx/resolver/native.rb', line 51 def terminate emit(:close, self) end |
#timeout ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/httpx/resolver/native.rb', line 94 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
59 60 61 |
# File 'lib/httpx/resolver/native.rb', line 59 def to_io @io.to_io end |