Feature #5100 ยป 0001-lib-resolv.rb-Resolv-DNS-implement-configurable-time.patch
lib/resolv.rb | ||
---|---|---|
@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
|
||
... | ... | |
@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)
|
||
... | ... | |
def resolv(name)
|
||
candidates = generate_candidates(name)
|
||
timeouts = generate_timeouts
|
||
timeouts = @timeouts || generate_timeouts
|
||
begin
|
||
candidates.each {|candidate|
|
||
begin
|
test/resolv/test_dns.rb | ||
---|---|---|
}
|
||
end
|
||
def test_query_ipv4_address_timeout
|
||
with_udp('127.0.0.1', 0) {|u|
|
||
_, port , _, host = u.addr
|
||
start = nil
|
||
rv = Resolv::DNS.open(:nameserver_port => [[host, port]]) {|dns|
|
||
dns.timeouts = 0.1
|
||
start = Time.now
|
||
dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
|
||
}
|
||
diff = Time.now - start
|
||
assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
|
||
assert_in_delta 0.1, diff, 0.05
|
||
rv = Resolv::DNS.open(:nameserver_port => [[host, port]]) {|dns|
|
||
dns.timeouts = [ 0.1, 0.2 ]
|
||
start = Time.now
|
||
dns.getresources("foo.example.org", Resolv::DNS::Resource::IN::A)
|
||
}
|
||
diff = Time.now - start
|
||
assert rv.empty?, "unexpected: #{rv.inspect} (expected empty)"
|
||
assert_in_delta 0.3, diff, 0.05
|
||
}
|
||
end
|
||
def test_no_server
|
||
u = UDPSocket.new
|
||
u.bind("127.0.0.1", 0)
|