diff options
Diffstat (limited to 'lib/resolv.rb')
-rw-r--r-- | lib/resolv.rb | 31 |
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 |