Class: Resolv::DNS::Requester

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/patches/resolv_9270.rb

Overview

:nodoc:

Direct Known Subclasses

ConnectedUDP, TCP, UnconnectedUDP

Defined Under Namespace

Classes: ConnectedUDP, MDNSOneShot, RequestError, Sender, TCP, UnconnectedUDP

Instance Method Summary collapse

Constructor Details

#initializeRequester

Returns a new instance of Requester.



675
676
677
678
# File 'lib/logstash/patches/resolv_9270.rb', line 675

def initialize
  @senders = {}
  @socks = nil
end

Instance Method Details

#closeObject



731
732
733
734
735
# File 'lib/logstash/patches/resolv_9270.rb', line 731

def close
  socks = @socks
  @socks = nil
  socks&.each(&:close)
end

#request(sender, tout) ⇒ Object



680
681
682
683
684
685
686
687
688
689
690
691
692
693
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
# File 'lib/logstash/patches/resolv_9270.rb', line 680

def request(sender, tout)
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  timelimit = start + tout
  begin
    sender.send
  rescue Errno::EHOSTUNREACH, # multi-homed IPv6 may generate this
      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, # GNU/Linux, FreeBSD
        Errno::ECONNRESET # Windows
      # No name server running on the server?
      # Don't wait anymore.
      raise ResolvTimeout
    end
    begin
      msg = Message.decode(reply)
    rescue DecodeError
      next # broken DNS message ignored
    end
    if s = sender_for(from, msg)
      break
    else
      # unexpected DNS message ignored
    end
  end
  return msg, s.data
end

#sender_for(addr, msg) ⇒ Object



727
728
729
# File 'lib/logstash/patches/resolv_9270.rb', line 727

def sender_for(addr, msg)
  @senders[[addr,msg.id]]
end