vendor/bundle/ruby/2.7.0/gems/dnsruby-1.61.5/lib/dnsruby/resolver.rb
#  This method is called by the SelectThread (in the select thread) when the queue has a new item on it.
#  The queue interface is used to separate producer/consumer threads, but we're using it here in one thread.
#  It's probably a good idea to create a new "worker thread" to take items from the select thread queue and
#  call this method in the worker thread.
#
This method is called by the SelectThread (in the select thread) when the queue has a new item on it.
The queue interface is used to separate producer/consumer threads, but we're using it here in one thread.
It's probably a good idea to create a new "worker thread" to take items from the select thread queue and
call this method in the worker thread.
This method is called by the SelectThread ( in the select thread ) when the queue has a new item on it . The queue interface is used to separate producer / consumer threads but we ' re using it here in one thread . It ' s probably a good idea to create a new " worker thread " to take items from the select thread queue and call this method in the worker thread .
def handle_queue_event(queue, id) 
        So, get the next response from the queue (presuming there is one!)
        @TODO@ Tick could poll the queue and then call this method if needed - no need for observer interface.
        @TODO@ Currently, tick and handle_queue_event called from select_thread - could have thread chuck events in to tick_queue. But then, clients would have to call in on other thread!
        So - two types of response :
        1) we've got a coherent response (or error) - stop sending more packets for that query!
        2) we've validated the response - it's ready to be sent to the client
        so need two more methods :
         handleValidationResponse : basically calls send_result_and_stop_querying and
         handleValidationError : does the same as handleValidationResponse, but for errors
        can leave handleError alone
        but need to change handleResponse to stop sending, rather than send_result_and_stop_querying.
        @TODO@ Also, we could really do with a MaxValidationTimeout - if validation not OK within
        this time, then raise Timeout (and stop validation)?
        @TODO@ Also, should there be some facility to stop validator following same chain
        concurrently?
        @TODO@ Also, should have option to speak only to configured resolvers (not follow authoritative chain)
      if queue.empty?
        log_and_raise('Severe internal error - Queue empty in handle_queue_event')
      end
      event_id, event_type, response, error = queue.pop
        We should remove this packet from the list of outstanding packets for this query
      _resolver, _msg, client_query_id, _retry_count = id
      if id != event_id
        log_and_raise("Serious internal error!! {id} expected, {event_id} received")
      end
             @mutex.synchronize{
      @parent.single_res_mutex.synchronize {
        if @query_list[client_query_id] == nil
                     print "Dead query response - ignoring\n"
          Dnsruby.log.debug{'Ignoring response for dead query'}
          return
        end
        _msg, _client_queue, _select_queue, outstanding = @query_list[client_query_id]
        if event_type == Resolver::EventType::RECEIVED ||
              event_type == Resolver::EventType::ERROR
          unless outstanding.include?(id)
            log_and_raise("Query id not on outstanding list! {outstanding.length} items. {id} not on {outstanding}")
          end
          outstanding.delete(id)
        end
               }
        if event_type == Resolver::EventType::RECEIVED
                 if (event.kind_of?(Exception))
          if error
            handle_error_response(queue, event_id, error, response)
          else  if event.kind_of?(Message)
            handle_response(queue, event_id, response)
                   else
                     Dnsruby.log.error('Random object {event.class} returned through queue to Resolver')
          end
        elsif event_type == Resolver::EventType::VALIDATED
          if error
            handle_validation_error(queue, event_id, error, response)
          else
            handle_validation_response(queue, event_id, response)
          end
        elsif event_type == Resolver::EventType::ERROR
          handle_error_response(queue, event_id, error, response)
        else
                     print "ERROR - UNKNOWN EVENT TYPE IN RESOLVER : {event_type}\n"
          TheLog.error("ERROR - UNKNOWN EVENT TYPE IN RESOLVER : {event_type}")
        end
      }
    end
def handle_queue_event ( queue , id ) if queue . empty? log_and_raise ( 'Severe internal error - Queue empty in handle_queue_event' ) end event_id , event_type , response , error = queue . pop _resolver , _msg , client_query_id , _retry_count = id if id != event_id log_and_raise ( "Serious internal error!! #{id} expected, #{event_id} received" ) end @parent . single_res_mutex . synchronize { if @query_list [ client_query_id ] == nil Dnsruby . log . debug { 'Ignoring response for dead query' } return end _msg , _client_queue , _select_queue , outstanding = @query_list [ client_query_id ] if event_type == Resolver :: EventType :: RECEIVED || event_type == Resolver :: EventType :: ERROR unless outstanding . include? ( id ) log_and_raise ( "Query id not on outstanding list! #{outstanding.length} items. #{id} not on #{outstanding}" ) end outstanding . delete ( id ) end if event_type == Resolver :: EventType :: RECEIVED if error handle_error_response ( queue , event_id , error , response ) else handle_response ( queue , event_id , response ) end elsif event_type == Resolver :: EventType :: VALIDATED if error handle_validation_error ( queue , event_id , error , response ) else handle_validation_response ( queue , event_id , response ) end elsif event_type == Resolver :: EventType :: ERROR handle_error_response ( queue , event_id , error , response ) else TheLog . error ( "ERROR - UNKNOWN EVENT TYPE IN RESOLVER : #{event_type}" ) end } end
This method is called by the SelectThread (in the select thread) when the queue has a new item on it.
This method is called by the SelectThread ( in the select thread ) when the queue has a new item on it .
# :nodoc: all #  Time to process a new queue event. #  If we get a callback for an ID we don't know about, don't worry - #  just ignore it. It may be for a query we've already completed. # #  So, get the next response from the queue (presuming there is one!) # #  @TODO@ Tick could poll the queue and then call this method if needed - no need for observer interface. #  @TODO@ Currently, tick and handle_queue_event called from select_thread - could have thread chuck events in to tick_queue. But then, clients would have to call in on other thread! # #  So - two types of response : #  1) we've got a coherent response (or error) - stop sending more packets for that query! #  2) we've validated the response - it's ready to be sent to the client # #  so need two more methods : #   handleValidationResponse : basically calls send_result_and_stop_querying and #   handleValidationError : does the same as handleValidationResponse, but for errors #  can leave handleError alone #  but need to change handleResponse to stop sending, rather than send_result_and_stop_querying. # #  @TODO@ Also, we could really do with a MaxValidationTimeout - if validation not OK within #  this time, then raise Timeout (and stop validation)? # #  @TODO@ Also, should there be some facility to stop validator following same chain #  concurrently? # #  @TODO@ Also, should have option to speak only to configured resolvers (not follow authoritative chain) # #  We should remove this packet from the list of outstanding packets for this query #       @mutex.synchronize{ #           print "Dead query response - ignoring\n" #       } #       if (event.kind_of?(Exception)) # if event.kind_of?(Message) #       else #         Dnsruby.log.error('Random object #{event.class} returned through queue to Resolver') #           print "ERROR - UNKNOWN EVENT TYPE IN RESOLVER : #{event_type}\n"
queue
<not_specific>
id
<not_specific>