Method: Dnsruby::ResolverRuby#tick
- Defined in:
- lib/dnsruby/resolver.rb
#tick ⇒ Object
This method is called twice a second from the select loop, in the select thread.
It should arguably be called from another worker thread... (which also handles the queue)
Each tick, we check if any timeouts have occurred. If so, we take the appropriate action :
Return a timeout to the client, or send a new query
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File 'lib/dnsruby/resolver.rb', line 985 def tick # :nodoc: all # Handle the tick # Do we have any retries due to be sent yet? # @mutex.synchronize{ @parent.single_res_mutex.synchronize { time_now = Time.now @timeouts.keys.each do |client_query_id| msg, client_queue, select_queue, outstanding = @query_list[client_query_id] query_timeout, timeouts = @timeouts[client_query_id] if query_timeout < Time.now # Time the query out (client_queue, client_query_id, select_queue, nil, ResolvTimeout.new('Query timed out')) next end timeouts_done = [] timeouts.keys.sort.each do |timeout| if timeout < time_now # Send the next query res, retry_count = timeouts[timeout] id = [res, msg, client_query_id, retry_count] Dnsruby.log.debug("Sending msg to #{res.server}") # We should keep a list of the queries which are outstanding outstanding.push(id) timeouts_done.push(timeout) timeouts.delete(timeout) # Pick a new QID here @TODO@ !!! # msg.header.id = rand(65535); # print "New query : #{new_msg}\n" res.send_async(msg, select_queue, id) else break end end timeouts_done.each { |t| timeouts.delete(t) } end } end |