Class: Resolv::DNS::Requester::UnconnectedUDP

Inherits:
Resolv::DNS::Requester show all
Defined in:
lib/net/dns/resolv.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Sender

Instance Method Summary collapse

Methods inherited from Resolv::DNS::Requester

#close, #delete

Constructor Details

#initializeUnconnectedUDP

Returns a new instance of UnconnectedUDP.



617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
# File 'lib/net/dns/resolv.rb', line 617

def initialize
  super()
  @sock = UDPSocket.new
  @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD
  @id = {}
  @id.default = -1
  @thread = Thread.new {
    DNSThreadGroup.add Thread.current
    loop {
      reply, from = @sock.recvfrom(UDPSize)
      msg = begin
        Message.decode(reply)
      rescue DecodeError
        STDERR.print("DNS message decoding error: #{reply.inspect}\n")
        next
      end
      if s = @senders[[[from[3],from[1]],msg.id]]
        s.recv msg
      else
        #STDERR.print("non-handled DNS message: #{msg.inspect} from #{from.inspect}\n")
      end
    }
  }
end

Instance Method Details

#sender(msg, data, queue, host, port = Port) ⇒ Object



642
643
644
645
646
647
648
649
650
651
# File 'lib/net/dns/resolv.rb', line 642

def sender(msg, data, queue, host, port=Port)
  service = [host, port]
  id = Thread.exclusive {
    @id[service] = (@id[service] + 1) & 0xffff
  }
  request = msg.encode
  request[0,2] = [id].pack('n')
  return @senders[[service, id]] =
    Sender.new(request, data, @sock, host, port, queue)
end