Class: Resolv::DNS::Requester::TCP
- Inherits:
-
Resolv::DNS::Requester
- Object
- Resolv::DNS::Requester
- Resolv::DNS::Requester::TCP
- Defined in:
- lib/net/dns/resolv.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Sender
Instance Method Summary collapse
-
#initialize(host, port = Port) ⇒ TCP
constructor
A new instance of TCP.
- #sender(msg, data, queue, host = @host, port = @port) ⇒ Object
Methods inherited from Resolv::DNS::Requester
Constructor Details
#initialize(host, port = Port) ⇒ TCP
Returns a new instance of TCP.
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/net/dns/resolv.rb', line 712 def initialize(host, port=Port) super() @host = host @port = port @sock = TCPSocket.new @sock.connect(host, port) @sock.fcntl(Fcntl::F_SETFD, 1) if defined? Fcntl::F_SETFD @id = -1 @senders = {} @thread = Thread.new { DNSThreadGroup.add Thread.current loop { len = @sock.read(2).unpack('n') reply = @sock.read(len) msg = begin Message.decode(reply) rescue DecodeError STDERR.print("DNS message decoding error: #{reply.inspect}") next end if s = @senders[msg.id] s.push msg else #STDERR.print("non-handled DNS message: #{msg.inspect}") end } } end |
Instance Method Details
#sender(msg, data, queue, host = @host, port = @port) ⇒ Object
741 742 743 744 745 746 747 748 749 |
# File 'lib/net/dns/resolv.rb', line 741 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] = [request.length, id].pack('nn') return @senders[id] = Sender.new(request, data, @sock, queue) end |