Class: Resolv::DNS::Requester::ConnectedUDP
- Inherits:
-
Resolv::DNS::Requester
- Object
- Resolv::DNS::Requester
- Resolv::DNS::Requester::ConnectedUDP
- Defined in:
- lib/logmerge/resolv.rb
Defined Under Namespace
Classes: Sender
Instance Method Summary collapse
-
#initialize(host, port = Port) ⇒ ConnectedUDP
constructor
A new instance of ConnectedUDP.
- #sender(msg, data, queue, host = @host, port = @port) ⇒ Object
Methods inherited from Resolv::DNS::Requester
Constructor Details
#initialize(host, port = Port) ⇒ ConnectedUDP
Returns a new instance of ConnectedUDP.
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/logmerge/resolv.rb', line 624 def initialize(host, port=Port) super() @host = host @port = port @sock = UDPSocket.new @sock.connect(host, port) @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD @id = -1 @thread = Thread.new { DNSThreadGroup.add Thread.current loop { reply = @sock.recv(UDPSize) msg = begin Message.decode(reply) rescue DecodeError STDERR.print("DNS message decoding error: #{reply.inspect}") next end if s = @senders[msg.id] s.recv msg else #STDERR.print("non-handled DNS message: #{msg.inspect}") end } } end |
Instance Method Details
#sender(msg, data, queue, host = @host, port = @port) ⇒ Object
651 652 653 654 655 656 657 658 659 |
# File 'lib/logmerge/resolv.rb', line 651 def sender(msg, data, queue, host=@host, port=@port) unless host == @host && port == @port raise RequestError.new("host/port don't match: #{host}:#{port}") end id = Thread.exclusive { @id = (@id + 1) & 0xffff } request = msg.encode request[0,2] = [id].pack('n') return @senders[id] = Sender.new(request, data, @sock, queue) end |