lib/rubydns/resolver.rb in rubydns-0.6.6 vs lib/rubydns/resolver.rb in rubydns-0.6.7

- old
+ new

@@ -82,10 +82,12 @@ request.callback do |message| yield message end request.errback do |error| + # In the case of a timeout, error will be nil, so we make one up. + yield error end request.run! end @@ -165,18 +167,24 @@ else raise InvalidProtocolError.new(@server) end # Setting up the timeout... - timeout(@timeout) do - @logger.debug "[#{@message.id}] Request timed out!" if @logger - - finish_request! - - try_next_server! - end + timeout(@timeout) else fail ResolutionFailure.new("No available servers responded to the request.") + end + end + + def timeout seconds + cancel_timeout + + @deferred_timeout = EventMachine::Timer.new(seconds) do + @logger.debug "[#{@message.id}] Request timed out!" if @logger + + finish_request! + + try_next_server! end end module UDPRequestHandler def self.open(host, port, request) \ No newline at end of file