Class: Resolv::DNS::Requester::ConnectedUDP
- Inherits:
-
Resolv::DNS::Requester
- Object
- Resolv::DNS::Requester
- Resolv::DNS::Requester::ConnectedUDP
- Defined in:
- lib/resolv.rb
Defined Under Namespace
Classes: Sender
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, port = Port) ⇒ ConnectedUDP
constructor
A new instance of ConnectedUDP.
- #recv_reply ⇒ Object
- #sender(msg, data, host = @host, port = @port) ⇒ Object
Methods inherited from Resolv::DNS::Requester
Constructor Details
#initialize(host, port = Port) ⇒ ConnectedUDP
Returns a new instance of ConnectedUDP.
675 676 677 678 679 680 681 682 683 |
# File 'lib/resolv.rb', line 675 def initialize(host, port=Port) super() @host = host @port = port @sock = UDPSocket.new(host.index(':') ? Socket::AF_INET6 : Socket::AF_INET) DNS.bind_random_port(@sock) @sock.connect(host, port) @sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD end |
Instance Method Details
#close ⇒ Object
700 701 702 703 704 705 |
# File 'lib/resolv.rb', line 700 def close super @senders.each_key {|from, id| DNS.free_request_id(@host, @port, id) } end |
#recv_reply ⇒ Object
685 686 687 688 |
# File 'lib/resolv.rb', line 685 def recv_reply reply = @sock.recv(UDPSize) return reply, nil end |
#sender(msg, data, host = @host, port = @port) ⇒ Object
690 691 692 693 694 695 696 697 698 |
# File 'lib/resolv.rb', line 690 def sender(msg, data, host=@host, port=@port) 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, @sock) end |