summaryrefslogtreecommitdiff
path: root/lib/resolv.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-22 08:46:12 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-22 08:46:12 +0000
commit16f4ecbc8cb83f0cadf02eb254623c27ea1946f1 (patch)
tree827e139be8cc22ed62a385a5f58b265bc7cfd5c6 /lib/resolv.rb
parentf600a558e03976679a9b8e5c24e14bb9c7d70916 (diff)
* lib/resolv.rb: make timeout configurable for DNS query.
patch by Eric Wong. [ruby-core:38533] [Feature #5100] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/resolv.rb')
-rw-r--r--lib/resolv.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 1e1889370a..89094a0ebf 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -336,6 +336,21 @@ class Resolv
@initialized = nil
end
+ # Sets the resolver timeouts. This may be a single positive number
+ # or an array of positive numbers representing timeouts in seconds.
+ # If an array is specified, a DNS request will retry and wait for
+ # each successive interval in the array until a successful response
+ # is received. Specifying +nil+ reverts to the default timeouts:
+ # [ 5, second = 5 * 2 / nameserver_count, 2 * second, 4 * second ]
+ #
+ # Example:
+ #
+ # dns.timeouts = 3
+ #
+ def timeouts=(values)
+ @config.timeouts = values
+ end
+
def lazy_initialize # :nodoc:
@mutex.synchronize {
unless @initialized
@@ -851,6 +866,20 @@ class Resolv
@mutex = Mutex.new
@config_info = config_info
@initialized = nil
+ @timeouts = nil
+ end
+
+ def timeouts=(values)
+ if values
+ values = Array(values)
+ values.each do |t|
+ Numeric === t or raise ArgumentError, "#{t.inspect} is not numeric"
+ t > 0.0 or raise Argument, "timeout=#{t} must be postive"
+ end
+ @timeouts = values
+ else
+ @timeouts = nil
+ end
end
def Config.parse_resolv_conf(filename)
@@ -1013,7 +1042,7 @@ class Resolv
def resolv(name)
candidates = generate_candidates(name)
- timeouts = generate_timeouts
+ timeouts = @timeouts || generate_timeouts
begin
candidates.each {|candidate|
begin