Class: Gem::Resolv::DNS::Requester
- Inherits:
-
Object
- Object
- Gem::Resolv::DNS::Requester
show all
- Defined in:
- lib/rubygems/vendor/resolv/lib/resolv.rb
Overview
Defined Under Namespace
Classes: ConnectedUDP, MDNSOneShot, RequestError, Sender, TCP, UnconnectedUDP
Instance Method Summary
collapse
Constructor Details
689
690
691
692
|
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 689
def initialize
@senders = {}
@socks = nil
end
|
Instance Method Details
#close ⇒ Object
745
746
747
748
749
|
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 745
def close
socks = @socks
@socks = nil
socks&.each(&:close)
end
|
#request(sender, tout) ⇒ Object
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
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/rubygems/vendor/resolv/lib/resolv.rb', line 694
def request(sender, tout)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
timelimit = start + tout
begin
sender.send
rescue Errno::EHOSTUNREACH,
Errno::ENETUNREACH
raise ResolvTimeout
end
while true
before_select = Process.clock_gettime(Process::CLOCK_MONOTONIC)
timeout = timelimit - before_select
if timeout <= 0
raise ResolvTimeout
end
if @socks.size == 1
select_result = @socks[0].wait_readable(timeout) ? [ @socks ] : nil
else
select_result = IO.select(@socks, nil, nil, timeout)
end
if !select_result
after_select = Process.clock_gettime(Process::CLOCK_MONOTONIC)
next if after_select < timelimit
raise ResolvTimeout
end
begin
reply, from = recv_reply(select_result[0])
rescue Errno::ECONNREFUSED,
Errno::ECONNRESET
raise ResolvTimeout
end
begin
msg = Message.decode(reply)
rescue DecodeError
next
end
if sender == sender_for(from, msg)
break
else
end
end
return msg, sender.data
end
|
#sender_for(addr, msg) ⇒ Object
741
742
743
|
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 741
def sender_for(addr, msg)
@senders[[addr,msg.id]]
end
|