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

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

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.



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/logmerge/resolv.rb', line 574

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



599
600
601
602
603
604
605
606
607
608
# File 'lib/logmerge/resolv.rb', line 599

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