Implementation of a synchronous name resolver which relies on the system resolver, which is lib’c getaddrinfo function (abstracted in ruby via Addrinfo.getaddrinfo).
Its main advantage is relying on the reference implementation for name resolution across most/all OSs which deploy ruby (it’s what TCPSocket also uses), its main disadvantage is the inability to set timeouts / check socket for readiness events, hence why it relies on using the Timeout module, which poses a lot of problems for the selector loop, specially when network is unstable.
Methods
Public Class
Public Instance
Constants
DONE | = | 1 | ||
ERROR | = | 2 | ||
RESOLV_ERRORS | = | [Resolv::ResolvError, Resolv::DNS::Requester::RequestError, Resolv::DNS::EncodeError, Resolv::DNS::DecodeError].freeze |
Attributes
state | [R] |
Public Class methods
new(options)
[show source]
# File lib/httpx/resolver/system.rb 34 def initialize(options) 35 super(0, options) 36 @resolver_options = @options.resolver_options 37 resolv_options = @resolver_options.dup 38 timeouts = resolv_options.delete(:timeouts) || Resolver::RESOLVE_TIMEOUT 39 @_timeouts = Array(timeouts) 40 @timeouts = Hash.new { |tims, host| tims[host] = @_timeouts.dup } 41 resolv_options.delete(:cache) 42 @queries = [] 43 @ips = [] 44 @pipe_mutex = Thread::Mutex.new 45 @state = :idle 46 end
Public Instance methods
<<(connection)
[show source]
# File lib/httpx/resolver/system.rb 98 def <<(connection) 99 @connections << connection 100 resolve 101 end
call()
[show source]
# File lib/httpx/resolver/system.rb 74 def call 75 case @state 76 when :open 77 consume 78 end 79 nil 80 end
close()
[show source]
# File lib/httpx/resolver/system.rb 62 def close 63 transition(:closed) 64 end
closed?()
[show source]
# File lib/httpx/resolver/system.rb 66 def closed? 67 @state == :closed 68 end
early_resolve(connection, **)
[show source]
# File lib/httpx/resolver/system.rb 103 def early_resolve(connection, **) 104 self << connection 105 true 106 end
handle_socket_timeout(interval)
[show source]
# File lib/httpx/resolver/system.rb 108 def handle_socket_timeout(interval) 109 error = HTTPX::ResolveTimeoutError.new(interval, "timed out while waiting on select") 110 error.set_backtrace(caller) 111 @queries.each do |host, connection| 112 @connections.delete(connection) 113 emit_resolve_error(connection, host, error) 114 end 115 116 while (connection = @connections.shift) 117 emit_resolve_error(connection, connection.peer.host, error) 118 end 119 end
interests()
[show source]
# File lib/httpx/resolver/system.rb 82 def interests 83 return if @queries.empty? 84 85 :r 86 end
resolvers()
[show source]
# File lib/httpx/resolver/system.rb 48 def resolvers 49 return enum_for(__method__) unless block_given? 50 51 yield self 52 end
timeout()
[show source]
# File lib/httpx/resolver/system.rb 88 def timeout 89 return unless @queries.empty? 90 91 _, connection = @queries.first 92 93 return unless connection 94 95 @timeouts[connection.peer.host].first 96 end