AnyEvent
view release on metacpan or search on metacpan
lib/AnyEvent/DNS.pm view on Meta::CPAN
=item timeout => [...]
A list of timeouts to use (also determines the number of retries). To make
three retries with individual time-outs of 2, 5 and 5 seconds, use C<[2,
5, 5]>, which is also the default.
=item search => [...]
The default search list of suffixes to append to a domain name (default: none).
=item ndots => $integer
The number of dots (default: C<1>) that a name must have so that the resolver
tries to resolve the name without any suffixes first.
=item max_outstanding => $integer
Most name servers do not handle many parallel requests very well. This
option limits the number of outstanding requests to C<$integer>
(default: C<10>), that means if you request more than this many requests,
then the additional requests will be queued until some other requests have
been resolved.
=item reuse => $seconds
The number of seconds (default: C<300>) that a query id cannot be re-used
after a timeout. If there was no time-out then query ids can be reused
immediately.
=item untaint => $boolean
When true, then the resolver will automatically untaint results, and might
also ignore certain environment variables.
=back
=cut
sub new {
my ($class, %arg) = @_;
my $self = bless {
server => [],
timeout => [2, 5, 5],
search => [],
ndots => 1,
max_outstanding => 10,
reuse => 300,
%arg,
inhibit => 0,
reuse_q => [],
}, $class;
# search should default to gethostname's domain
# but perl lacks a good posix module
# try to create an ipv4 and an ipv6 socket
# only fail when we cannot create either
my $got_socket;
Scalar::Util::weaken (my $wself = $self);
if (socket my $fh4, AF_INET , Socket::SOCK_DGRAM(), 0) {
++$got_socket;
AnyEvent::fh_unblock $fh4;
$self->{fh4} = $fh4;
$self->{rw4} = AE::io $fh4, 0, sub {
if (my $peer = recv $fh4, my $pkt, MAX_PKT, 0) {
$wself->_recv ($pkt, $peer);
}
};
}
if (AF_INET6 && socket my $fh6, AF_INET6, Socket::SOCK_DGRAM(), 0) {
++$got_socket;
$self->{fh6} = $fh6;
AnyEvent::fh_unblock $fh6;
$self->{rw6} = AE::io $fh6, 0, sub {
if (my $peer = recv $fh6, my $pkt, MAX_PKT, 0) {
$wself->_recv ($pkt, $peer);
}
};
}
$got_socket
or Carp::croak "unable to create either an IPv4 or an IPv6 socket";
$self->_compile;
$self
}
# called to start asynchronous configuration
sub _config_begin {
++$_[0]{inhibit};
}
# called when done with async config
sub _config_done {
--$_[0]{inhibit};
$_[0]->_compile;
$_[0]->_scheduler;
}
=item $resolver->parse_resolv_conf ($string)
Parses the given string as if it were a F<resolv.conf> file. The following
directives are supported (but not necessarily implemented).
C<#>- and C<;>-style comments, C<nameserver>, C<domain>, C<search>, C<sortlist>,
C<options> (C<timeout>, C<attempts>, C<ndots>).
Everything else is silently ignored.
=cut
sub parse_resolv_conf {
my ($self, $resolvconf) = @_;
( run in 2.112 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )