Class: Resolv::DNS::Requester::ConnectedUDP
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
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(host, port = Port) ⇒ ConnectedUDP
# File 'lib/resolv.rb', line 819
def initialize(host, port=Port) super() @host = host @port = port @mutex = Thread::Mutex.new @initialized = false end
Instance Method Details
#close
[ GitHub ]# File 'lib/resolv.rb', line 858
def close @mutex.synchronize do if @initialized super @senders.each_key {|from, id| DNS.free_request_id(@host, @port, id) } @initialized = false end end end
#lazy_initialize
[ GitHub ]# File 'lib/resolv.rb', line 827
def lazy_initialize @mutex.synchronize { next if @initialized @initialized = true is_ipv6 = @host.index(':') sock = UDPSocket.new(is_ipv6 ? Socket::AF_INET6 : Socket::AF_INET) @socks = [sock] sock.do_not_reverse_lookup = true DNS.bind_random_port(sock, is_ipv6 ? "::" : "0.0.0.0") sock.connect(@host, @port) } self end
#recv_reply(readable_socks)
[ GitHub ]# File 'lib/resolv.rb', line 841
def recv_reply(readable_socks) lazy_initialize reply = readable_socks[0].recv(UDPSize) return reply, nil end
#sender(msg, data, host = @host, port = @port)
[ GitHub ]# File 'lib/resolv.rb', line 847
def sender(msg, data, host=@host, port=@port) lazy_initialize unless host == @host && port == @port raise RequestError.new("host/port don't match: #{host}:#{port}") end id = DNS.allocate_request_id(@host, @port) request = msg.encode request[0,2] = [id].pack('n') return @senders[[nil,id]] = Sender.new(request, data, @socks[0]) end