Class: Resolv::DNS::Requester::ConnectedUDP
- Inherits:
-
Resolv::DNS::Requester
- Object
- Resolv::DNS::Requester
- Resolv::DNS::Requester::ConnectedUDP
- Defined in:
- lib/resolv.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Sender
Instance Method Summary (collapse)
- - (Object) close
-
- (ConnectedUDP) initialize(host, port = Port)
constructor
A new instance of ConnectedUDP.
- - (Object) recv_reply(readable_socks)
- - (Object) sender(msg, data, host = @host, port = @port)
Methods inherited from Resolv::DNS::Requester
Constructor Details
- (ConnectedUDP) initialize(host, port = Port)
A new instance of ConnectedUDP
733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/resolv.rb', line 733 def initialize(host, port=Port) super() @host = host @port = port is_ipv6 = host.index(':') sock = UDPSocket.new(is_ipv6 ? Socket::AF_INET6 : Socket::AF_INET) @socks = [sock] sock.do_not_reverse_lookup = true sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD DNS.bind_random_port(sock, is_ipv6 ? "::" : "0.0.0.0") sock.connect(host, port) end |
Instance Method Details
- (Object) close
761 762 763 764 765 766 |
# File 'lib/resolv.rb', line 761 def close super @senders.each_key {|from, id| DNS.free_request_id(@host, @port, id) } end |
- (Object) recv_reply(readable_socks)
746 747 748 749 |
# File 'lib/resolv.rb', line 746 def recv_reply(readable_socks) reply = readable_socks[0].recv(UDPSize) return reply, nil end |
- (Object) sender(msg, data, host = @host, port = @port)
751 752 753 754 755 756 757 758 759 |
# File 'lib/resolv.rb', line 751 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, @socks[0]) end |