Unverified Commit ccc50085 authored by Gavin Brown's avatar Gavin Brown
Browse files

instantiate and configure the resolver object in a single shot

parent beae6dd4
...@@ -236,51 +236,52 @@ sub main_loop { ...@@ -236,51 +236,52 @@ sub main_loop {
sub time_query { sub time_query {
my ($family, $proto, @servers) = @_; my ($family, $proto, @servers) = @_;
return undef if (scalar(@servers) < 1); if (scalar(@servers) < 1) {
warn('received an empty set of nameservers');
return undef;
# } else {
# construct and configure a new resolver object #
# # construct a resolver
my $resolver = Net::DNS::Resolver->new; #
$resolver->retry(0); my $resolver = Net::DNS::Resolver->new(
$resolver->igntc(1); 'nameservers' => \@servers,
$resolver->usevc('tcp' eq $proto); 'retry' => 0,
$resolver->udp_timeout($CONF->{'Timeout'}); 'igntc' => 1,
$resolver->tcp_timeout($CONF->{'Timeout'}); 'usevc' => ('tcp' eq $proto),
$resolver->persistent_udp(0); 'udp_timeout' => $CONF->{'Timeout'},
$resolver->persistent_tcp(0); 'tcp_timeout' => $CONF->{'Timeout'},
$resolver->force_v4(4 == $family); 'persistent_udp' => 0,
$resolver->force_v6(6 == $family); 'persistent_tcp' => 0,
'force_v4' => 4 == $family,
# 'force_v6' => 6 == $family,
# specify nameservers );
#
$resolver->nameservers(@servers); my $result;
my $result;
my $t0 = time(); my $t0 = time();
# #
# send query inside an eval to catch errors # send query inside an eval to catch errors
# #
eval { eval {
$result = $resolver->send($PACKET); $result = $resolver->send($PACKET);
}; };
my $dt = (time() - $t0); my $dt = (time() - $t0);
if ($@) { if ($@) {
chomp($@); chomp($@);
debug($@); debug($@);
} }
if (!$result || (defined($CONF->{'ResponseCode'}) && $result->header->rcode ne $CONF->{'ResponseCode'})) { if (!$result || (defined($CONF->{'ResponseCode'}) && $result->header->rcode ne $CONF->{'ResponseCode'})) {
return undef; return undef;
} else { } else {
return $dt; return $dt;
}
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment