Class: Resolv::DNS::Requester::UnconnectedUDP
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Resolv::DNS::Requester
|
|
Instance Chain:
self,
::Resolv::DNS::Requester
|
|
Inherits: |
Resolv::DNS::Requester
|
Defined in: | lib/resolv.rb |
Class Method Summary
Instance Method Summary
::Resolv::DNS::Requester - Inherited
Constructor Details
.new(*nameserver_port) ⇒ UnconnectedUDP
# File 'lib/resolv.rb', line 734
def initialize(*nameserver_port) super() @nameserver_port = nameserver_port @initialized = false @mutex = Thread::Mutex.new end
Instance Method Details
#close
[ GitHub ]# File 'lib/resolv.rb', line 788
def close @mutex.synchronize { if @initialized super @senders.each_key {|service, id| DNS.free_request_id(service[0], service[1], id) } @initialized = false end } end
#lazy_initialize
[ GitHub ]# File 'lib/resolv.rb', line 741
def lazy_initialize @mutex.synchronize { next if @initialized @initialized = true @socks_hash = {} @socks = [] @nameserver_port.each {|host, port| if host.index(':') bind_host = "::" af = Socket::AF_INET6 else bind_host = "0.0.0.0" af = Socket::AF_INET end next if @socks_hash[bind_host] begin sock = UDPSocket.new(af) rescue Errno::EAFNOSUPPORT next # The kernel doesn't support the address family. end @socks << sock @socks_hash[bind_host] = sock sock.do_not_reverse_lookup = true DNS.bind_random_port(sock, bind_host) } } self end
#recv_reply(readable_socks)
[ GitHub ]# File 'lib/resolv.rb', line 770
def recv_reply(readable_socks) lazy_initialize reply, from = readable_socks[0].recvfrom(UDPSize) return reply, [from[3],from[1]] end
#sender(msg, data, host, port = Port)
[ GitHub ]# File 'lib/resolv.rb', line 776
def sender(msg, data, host, port=Port) lazy_initialize sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"] return nil if !sock service = [host, port] id = DNS.allocate_request_id(host, port) request = msg.encode request[0,2] = [id].pack('n') return @senders[[service, id]] = Sender.new(request, data, sock, host, port) end