Methods
Public Class
Public Instance
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 24 def initialize(family, options) 25 super 26 @ns_index = 0 27 @resolver_options = DEFAULTS.merge(@options.resolver_options) 28 @socket_type = @resolver_options.fetch(:socket_type, :udp) 29 @nameserver = if (nameserver = @resolver_options[:nameserver]) 30 nameserver = nameserver[family] if nameserver.is_a?(Hash) 31 Array(nameserver) 32 end 33 @ndots = @resolver_options.fetch(:ndots, 1) 34 @search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) } 35 @_timeouts = Array(@resolver_options[:timeouts]) 36 @timeouts = Hash.new { |timeouts, host| timeouts[host] = @_timeouts.dup } 37 @connections = [] 38 @queries = {} 39 @read_buffer = "".b 40 @write_buffer = Buffer.new(@resolver_options[:packet_size]) 41 @state = :idle 42 end
Public Instance methods
<<(connection)
[show source]
# File lib/httpx/resolver/native.rb 88 def <<(connection) 89 if @nameserver.nil? 90 ex = ResolveError.new("No available nameserver") 91 ex.set_backtrace(caller) 92 connection.force_reset 93 throw(:resolve_error, ex) 94 else 95 @connections << connection 96 resolve 97 end 98 end
call()
[show source]
# File lib/httpx/resolver/native.rb 56 def call 57 case @state 58 when :open 59 consume 60 end 61 nil 62 rescue Errno::EHOSTUNREACH => e 63 @ns_index += 1 64 nameserver = @nameserver 65 if nameserver && @ns_index < nameserver.size 66 log { "resolver: failed resolving on nameserver #{@nameserver[@ns_index - 1]} (#{e.message})" } 67 transition(:idle) 68 @timeouts.clear 69 else 70 handle_error(e) 71 end 72 rescue NativeResolveError => e 73 handle_error(e) 74 end
close()
[show source]
# File lib/httpx/resolver/native.rb 44 def close 45 transition(:closed) 46 end
closed?()
[show source]
# File lib/httpx/resolver/native.rb 48 def closed? 49 @state == :closed 50 end
handle_socket_timeout(interval)
[show source]
# File lib/httpx/resolver/native.rb 108 def handle_socket_timeout(interval) 109 do_retry(interval) 110 end
interests()
[show source]
# File lib/httpx/resolver/native.rb 76 def interests 77 case @state 78 when :idle 79 transition(:open) 80 when :closed 81 transition(:idle) 82 transition(:open) 83 end 84 85 calculate_interests 86 end
timeout()
[show source]
# File lib/httpx/resolver/native.rb 100 def timeout 101 return if @connections.empty? 102 103 @start_timeout = Utils.now 104 hosts = @queries.keys 105 @timeouts.values_at(*hosts).reject(&:empty?).map(&:first).min 106 end