Class: Gem::Resolv::DNS::Requester::UnconnectedUDP
- Inherits:
-
Gem::Resolv::DNS::Requester
- Object
- Gem::Resolv::DNS::Requester
- Gem::Resolv::DNS::Requester::UnconnectedUDP
- Defined in:
- lib/rubygems/vendor/resolv/lib/resolv.rb
Overview
:nodoc:
Direct Known Subclasses
Defined Under Namespace
Classes: Sender
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(*nameserver_port) ⇒ UnconnectedUDP
constructor
A new instance of UnconnectedUDP.
- #lazy_initialize ⇒ Object
- #recv_reply(readable_socks) ⇒ Object
- #sender(msg, data, host, port = Port) ⇒ Object
Methods inherited from Gem::Resolv::DNS::Requester
Constructor Details
#initialize(*nameserver_port) ⇒ UnconnectedUDP
Returns a new instance of UnconnectedUDP.
745 746 747 748 749 750 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 745 def initialize(*nameserver_port) super() @nameserver_port = nameserver_port @initialized = false @mutex = Thread::Mutex.new end |
Instance Method Details
#close ⇒ Object
800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 800 def close @mutex.synchronize { if @initialized super @senders.each_key {|service, id| DNS.free_request_id(service[0], service[1], id) } @initialized = false end } end |
#lazy_initialize ⇒ Object
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 752 def lazy_initialize @mutex.synchronize { next if @initialized @initialized = true @socks_hash = {} @socks = [] @nameserver_port.each {|host, port| if host.index(':') bind_host = "::" af = Socket::AF_INET6 else bind_host = "0.0.0.0" af = Socket::AF_INET end next if @socks_hash[bind_host] begin sock = UDPSocket.new(af) rescue Errno::EAFNOSUPPORT, Errno::EPROTONOSUPPORT next # The kernel doesn't support the address family. end @socks << sock @socks_hash[bind_host] = sock sock.do_not_reverse_lookup = true DNS.bind_random_port(sock, bind_host) } } self end |
#recv_reply(readable_socks) ⇒ Object
781 782 783 784 785 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 781 def recv_reply(readable_socks) lazy_initialize reply, from = readable_socks[0].recvfrom(UDPSize) return reply, [from[3],from[1]] end |
#sender(msg, data, host, port = Port) ⇒ Object
787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 787 def sender(msg, data, host, port=Port) host = Addrinfo.ip(host).ip_address lazy_initialize sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"] return nil if !sock service = [host, port] id = DNS.allocate_request_id(host, port) request = msg.encode request[0,2] = [id].pack('n') return @senders[[service, id]] = Sender.new(request, data, sock, host, port) end |