Class: Resolv::DNS
- Inherits:
-
Object
- Object
- Resolv::DNS
- Defined in:
- lib/spf/ext/resolv.rb,
lib/spf/ext/resolv.rb,
lib/spf/ext/resolv.rb
Defined Under Namespace
Instance Method Summary collapse
- #each_resource(name, typeclass, &proc) ⇒ Object
-
#make_tcp_requester(host, port) ⇒ Object
alias_method :make_udp_requester, :make_requester.
Instance Method Details
#each_resource(name, typeclass, &proc) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/spf/ext/resolv.rb', line 15 def each_resource(name, typeclass, &proc) lazy_initialize protocols = {} # PATCH requesters = {} # PATCH senders = {} #begin # PATCH @config.resolv(name) {|candidate, tout, nameserver, port| msg = Message.new msg.rd = 1 msg.add_question(candidate, typeclass) protocol = protocols[candidate] ||= :udp # PATCH requester = requesters[[protocol, nameserver]] ||= case protocol # PATCH when :udp then make_udp_requester # PATCH when :tcp then make_tcp_requester(nameserver, port) # PATCH end # PATCH sender = senders[[candidate, requester, nameserver, port]] ||= # PATCH requester.sender(msg, candidate, nameserver, port) # PATCH reply, reply_name = requester.request(sender, tout) case reply.rcode when RCode::NoError if protocol == :udp and reply.tc == 1 # PATCH # Retry via TCP: # PATCH protocols[candidate] = :tcp # PATCH redo # PATCH else # PATCH extract_resources(reply, reply_name, typeclass, &proc) end # PATCH return when RCode::NXDomain raise Config::NXDomain.new(reply_name.to_s) else raise Config::OtherResolvError.new(reply_name.to_s) end } ensure requesters.each_value { |requester| requester.close } # PATCH #end # PATCH end |
#make_tcp_requester(host, port) ⇒ Object
alias_method :make_udp_requester, :make_requester
56 57 58 59 60 61 62 63 |
# File 'lib/spf/ext/resolv.rb', line 56 def make_tcp_requester(host, port) return Requester::TCP.new(host, port) rescue Errno::ECONNREFUSED # Treat a refused TCP connection attempt to a nameserver like a timeout, # as Resolv::DNS::Config#resolv considers ResolvTimeout exceptions as a # hint to try the next nameserver: raise ResolvTimeout end |