/usr/share/perl5/POE/Component/Resolver.pm is in libpoe-component-resolver-perl 0.920-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | package POE::Component::Resolver;
{
$POE::Component::Resolver::VERSION = '0.920';
}
use warnings;
use strict;
use POE qw(Wheel::Run Filter::Reference);
use Carp qw(croak carp);
use Time::HiRes qw(time);
use Socket qw(
unpack_sockaddr_in AF_INET AF_INET6
getnameinfo NI_NUMERICSERV NI_NUMERICHOST
);
use POE::Component::Resolver::Sidecar;
use Exporter;
use base 'Exporter';
our (@EXPORT_OK) = qw(AF_INET AF_INET6);
my $next_alias_index = "aaaaaaaa";
# Determine Perl's location, per perldoc perlvar's treatment of $^X.
use Config;
my $perl_path = $Config{perlpath};
if ($^O ne 'VMS') {
$perl_path .= $Config{_exe} unless (
$perl_path =~ /$Config{_exe}$/i
);
}
# Plain Perl constructor.
sub new {
my ($class, @args) = @_;
croak "new() requires an even number of parameters" if @args % 2;
my %args = @args;
my $max_resolvers = delete($args{max_resolvers}) || 8;
my $idle_timeout = delete($args{idle_timeout}) || 15;
my $debug = delete($args{debug}) || 0;
my $sidecar_program = delete($args{sidecar_program});
my $af_order = delete($args{af_order});
if (defined $af_order and @$af_order) {
if (ref($af_order) eq "") {
$af_order = [ $af_order ];
}
elsif (ref($af_order) ne "ARRAY") {
croak "af_order must be a scalar or an array reference";
}
my @illegal_afs = grep { ($_ ne AF_INET) && ($_ ne AF_INET6) } @$af_order;
croak "af_order may only contain AF_INET and/or AF_INET6" if @illegal_afs;
}
elsif (exists $ENV{POCO_RESOLVER_IPV}) {
my %number_to_address_family = ( 4 => AF_INET, 6 => AF_INET6 );
$af_order = [
map { $number_to_address_family{$_} }
($ENV{POCO_RESOLVER_IPV} =~ m/([46])/g)
];
}
unless ($af_order and @$af_order) {
# Default to IPv4 preference for backward compatibility.
$af_order = [ AF_INET, AF_INET6 ];
}
my @error = sort keys %args;
croak "unknown new() parameter(s): @error" if @error;
unless (defined $sidecar_program and length $sidecar_program) {
if ($^O eq "MSWin32") {
$sidecar_program = \&POE::Component::Resolver::Sidecar::main;
}
else {
$sidecar_program = [
$perl_path,
(map { "-I$_" } @INC),
'-MPOE::Component::Resolver::Sidecar',
'-e', 'POE::Component::Resolver::Sidecar->main()'
];
}
}
my $self = bless {
alias => "poe_component_resolver_" . $next_alias_index++,
debug => $debug,
}, $class;
POE::Session->create(
inline_states => {
_start => \&_poe_start,
_stop => \&_poe_stop,
_parent => sub { undef }, # for ASSERT_DEFAULT
_child => sub { undef }, # for ASSERT_DEFAULT
request => \&_poe_request,
shutdown => \&_poe_shutdown,
cancel => \&_poe_cancel,
sidecar_closed => \&_poe_sidecar_closed,
sidecar_error => \&_poe_sidecar_error,
sidecar_response => \&_poe_sidecar_response,
sidecar_signal => \&_poe_sidecar_signal,
sidecar_eject => \&_poe_sidecar_eject,
sidecar_attach => \&_poe_sidecar_attach,
},
heap => {
af_order => $af_order,
alias => $self->{alias},
idle_timeout => $idle_timeout,
last_request_id => 0,
max_resolvers => $max_resolvers,
requests => { },
sidecar_ring => [ ],
sidecar_program => $sidecar_program,
debug => $debug,
}
);
return $self;
}
sub DESTROY {
my $self = shift;
# Can't resolve the session: it must already be gone.
return unless $poe_kernel->alias_resolve($self->{alias});
carp "<pcr> destroying $self->{alias}" if $self->{debug};
$poe_kernel->call($self->{alias}, "shutdown");
}
sub _poe_stop {
my $heap = $_[HEAP];
carp "<pcr> stopping $heap->{alias}" if $heap->{debug};
}
sub shutdown {
my $self = shift;
# Can't resolve the session: it must already be gone.
return unless $poe_kernel->alias_resolve($self->{alias});
carp "<pcr> got shutdown request for $self->{alias}" if $self->{debug};
$poe_kernel->call($self->{alias}, "shutdown");
}
# Internal POE event handler to release all resources owned by the
# hidden POE::Session and then shut it down. It's an event handler so
# that this code can run "within" the POE::Session.
sub _poe_shutdown {
my ($kernel, $heap) = @_[KERNEL, HEAP];
$heap->{shutdown} = 1;
$kernel->alias_remove($heap->{alias});
_poe_wipe_sidecars($heap);
foreach my $request (values %{$heap->{requests}}) {
$kernel->post(
$request->{sender},
$request->{event},
'component shut down',
[ ],
{ map { $_ => $request->{$_} } qw(host service misc) },
);
warn "<pcr> $heap->{alias} --refcount for sender $request->{sender}" if (
$heap->{debug}
);
$kernel->refcount_decrement($request->{sender}, __PACKAGE__);
}
$heap->{requests} = {};
# No more sidecars to eject.
$kernel->delay(sidecar_eject => undef);
}
# POE event handler to accept a request from some other session. The
# public Perl resolve() method forwards into this. This runs "within"
# the session so the resources it creates are properly owned.
sub _poe_request {
my ($kernel, $heap, $host, $service, $hints, $event, $misc) = @_[
KERNEL, HEAP, ARG0..ARG4
];
return if $heap->{shutdown};
my $request_id = ++$heap->{last_request_id};
my $sender_id = $_[SENDER]->ID();
warn "<pcr> $heap->{alias} ++refcount for sender $sender_id" if (
$heap->{debug}
);
$kernel->refcount_increment($sender_id, __PACKAGE__);
_poe_setup_sidecar_ring($kernel, $heap);
my $next_sidecar = pop @{$heap->{sidecar_ring}};
unshift @{$heap->{sidecar_ring}}, $next_sidecar;
$next_sidecar->put( [ $request_id, $host, $service, $hints ] );
$heap->{requests}{$request_id} = {
begin => time(),
host => $host,
service => $service,
hints => $hints,
sender => $sender_id,
event => $event,
misc => $misc,
sidecar_id => $next_sidecar->ID(),
};
# No ejecting until we're done.
$kernel->delay(sidecar_eject => undef);
return $request_id;
}
# The user wishes to cancel a DNS request that may still be in
# progress. This can happen in places like PoCo::Client::HTTP when
# the HTTP request times out before the DNS request is done.
#
# The public cancel() API forwards the cancelation request into the
# POE::Session managing requests via POE::Kernel's call() method.
sub cancel {
my ($self, $request_id) = @_;
return $poe_kernel->call($self->{alias}, "cancel", $request_id);
}
# The inside-POE cancelation code. It must run within POE so that the
# proper resources are removed from the correct session.
sub _poe_cancel {
my ($kernel, $heap, $request_id) = @_[KERNEL, HEAP, ARG0];
return unless exists $heap->{requests}{$request_id};
my $request = $heap->{requests}{$request_id};
_sidecar_cleanup($kernel, $heap, $request->{sidecar_id});
}
# POE _start handler. Initialize the session and start sidecar
# processes, which are owned and managed by that session.
sub _poe_start {
my ($kernel, $heap) = @_[KERNEL, HEAP];
carp "<pcr> starting $heap->{alias}" if $heap->{debug};
$kernel->alias_set($heap->{alias});
#_poe_setup_sidecar_ring($kernel, $heap);
undef;
}
# Internal helper sub. Make sure the apprpriate number of sidecar
# resolvers are running at any given time.
sub _poe_setup_sidecar_ring {
my ($kernel, $heap) = @_;
return if $heap->{shutdown};
while (scalar(keys %{$heap->{sidecar}}) < $heap->{max_resolvers}) {
my $sidecar = POE::Wheel::Run->new(
StdioFilter => POE::Filter::Reference->new(),
StdoutEvent => 'sidecar_response',
StderrEvent => 'sidecar_error',
CloseEvent => 'sidecar_closed',
Program => $heap->{sidecar_program},
);
$heap->{sidecar}{$sidecar->PID} = $sidecar;
$heap->{sidecar_id}{$sidecar->ID} = $sidecar;
push @{$heap->{sidecar_ring}}, $sidecar;
$kernel->sig_child($sidecar->PID(), "sidecar_signal");
}
}
# Internal helper sub to replay pending requests when their associated
# sidecars are destroyed.
sub _poe_replay_pending {
my ($kernel, $heap) = @_;
while (my ($request_id, $request) = each %{$heap->{requests}}) {
# This request is riding in an existing sidecar.
# No need to replay it.
next if exists $heap->{sidecar_id}{$request->{sidecar_id}};
# Give the request to a new sidecar.
my $next_sidecar = pop @{$heap->{sidecar_ring}};
unshift @{$heap->{sidecar_ring}}, $next_sidecar;
$request->{sidecar_id} = $next_sidecar->ID();
$next_sidecar->put(
[
$request_id, $request->{host}, $request->{service}, $request->{hints}
]
);
}
}
# Internal event handler to briefly defer replaying requests until any
# responses in the queue have had time to be delivered. This prevents
# us from replaying requests that may already have answers.
sub _poe_sidecar_attach {
my ($kernel, $heap) = @_[KERNEL, HEAP];
# Nothing to do if we don't have requests.
return unless scalar keys %{$heap->{requests}};
# Requests exist.
_poe_setup_sidecar_ring($kernel, $heap);
_poe_replay_pending($kernel, $heap);
}
# Plain public Perl method. Begin resolving something.
sub resolve {
my ($self, @args) = @_;
croak "resolve() requires an even number of parameters" if @args % 2;
my %args = @args;
my $host = delete $args{host};
croak "resolve() requires a host" unless defined $host and length $host;
my $service = delete $args{service};
croak "resolve() requires a service" unless (
defined $service and length $service
);
my $misc = delete $args{misc};
$misc = "" unless defined $misc;
my $hints = delete $args{hints};
$hints ||= { };
my $event = delete $args{event};
$event = "resolver_response" unless defined $event and length $event;
my @error = sort keys %args;
croak "unknown resolve() parameter(s): @error" if @error;
my $result;
croak "resolve() on shutdown resolver" unless (
$result = $poe_kernel->call(
$self->{alias}, "request", $host, $service, $hints, $event, $misc
)
);
carp "<pcr> $self->{alias} request for host($host) service($service)" if (
$self->{debug}
);
return $result;
}
# A sidecar process has produced an error or warning. Pass it
# through to the parent process' console.
sub _poe_sidecar_error {
warn __PACKAGE__, " error in getaddrinfo subprocess: $_[ARG0]\n";
}
# A sidecar process has closed its standard output. We will receive
# no more responses from it. Clean up the sidecar's resources, and
# start new ones if necessary.
sub _poe_sidecar_closed {
my ($kernel, $heap, $wheel_id) = @_[KERNEL, HEAP, ARG0];
# Don't bother checking for pending requests if we've shut down.
return if $heap->{shutdown};
_sidecar_cleanup($kernel, $heap, $wheel_id);
}
sub _sidecar_cleanup {
my ($kernel, $heap, $wheel_id) = @_;
my $sidecar = delete $heap->{sidecar_id}{$wheel_id};
if (defined $sidecar) {
$sidecar->kill(9);
delete $heap->{sidecar}{$sidecar->PID()};
}
# Remove the sidecar from the rotation.
my $i = @{$heap->{sidecar_ring}};
while ($i--) {
next unless $heap->{sidecar_ring}[$i]->ID() == $wheel_id;
splice(@{$heap->{sidecar_ring}}, $i, 1);
last;
}
_poe_setup_sidecar_ring($kernel, $heap);
_poe_replay_pending($kernel, $heap) if scalar keys %{$heap->{requests}};
}
# A sidecar has produced a response. Pass it back to the original
# caller of resolve(). If we've run out of requests, briefly defer a
# partial shutdown. We don't need all those sidecar processes if we
# might be done.
sub _poe_sidecar_response {
my ($kernel, $heap, $response_rec) = @_[KERNEL, HEAP, ARG0];
my ($request_id, $error, $addresses) = @$response_rec;
my $request_rec = delete $heap->{requests}{$request_id};
return unless defined $request_rec;
if (defined $heap->{af_order}) {
my @filtered_addresses;
foreach my $af_filter (@{$heap->{af_order}}) {
push @filtered_addresses, grep { $_->{family} == $af_filter } @$addresses;
}
$addresses = \@filtered_addresses;
}
$kernel->post(
$request_rec->{sender}, $request_rec->{event},
$error, $addresses,
{ map { $_ => $request_rec->{$_} } qw(host service misc) },
);
warn "<pcr> $heap->{alias} --refcount for sender $request_rec->{sender}" if (
$heap->{debug}
);
$kernel->refcount_decrement($request_rec->{sender}, __PACKAGE__);
# No more requests? Consder detaching sidecar.
$kernel->delay(sidecar_eject => $heap->{idle_timeout}) unless (
scalar keys %{$heap->{requests}}
);
}
# A sidecar process has exited. Clean up its resources, and attach a
# replacement sidecar if there are requests.
sub _poe_sidecar_signal {
my ($heap, $pid) = @_[HEAP, ARG1];
return unless exists $heap->{sidecar}{$pid};
my $sidecar = delete $heap->{sidecar}{$pid};
my $sidecar_id = $sidecar->ID();
delete $heap->{sidecar_id}{$sidecar_id};
# Remove the sidecar from the rotation.
my $i = @{$heap->{sidecar_ring}};
while ($i--) {
next unless $heap->{sidecar_ring}[$i]->ID() == $sidecar_id;
splice(@{$heap->{sidecar_ring}}, 1, 1);
last;
}
$_[KERNEL]->yield("sidecar_attach") if scalar keys %{$heap->{requests}};
undef;
}
# Event handler to defer wiping out all sidecars. This allows for
# lazy cleanup, which may eliminate thrashing in some situations.
sub _poe_sidecar_eject {
my ($kernel, $heap) = @_[KERNEL, HEAP];
_poe_wipe_sidecars($heap) unless scalar keys %{$heap->{requests}};
}
# Internal helper sub to synchronously wipe out all sidecars.
sub _poe_wipe_sidecars {
my $heap = shift;
return unless @{$heap->{sidecar_ring}};
foreach my $sidecar (@{$heap->{sidecar_ring}}) {
$sidecar->kill(-9);
}
$heap->{sidecar} = {};
$heap->{sidecar_id} = {};
$heap->{sidecar_ring} = [];
}
sub unpack_addr {
my ($self, $address_rec) = @_;
# [rt.cpan.org 76314] Untaint the address.
my ($input_addr) = ($address_rec->{addr} =~ /\A(.*)\z/s);
my ($error, $address, $port) = (
(getnameinfo $input_addr, NI_NUMERICHOST | NI_NUMERICSERV)[0,1]
);
return if $error;
return($address, $port) if wantarray();
return $address;
}
1;
__END__
=head1 NAME
POE::Component::Resolver - A non-blocking getaddrinfo() resolver
=head1 VERSION
version 0.920
=head1 SYNOPSIS
#!/usr/bin/perl
use warnings;
use strict;
use POE;
use POE::Component::Resolver qw(AF_INET AF_INET6);
my $r = POE::Component::Resolver->new(
max_resolvers => 8,
idle_timeout => 5,
af_order => [ AF_INET6, AF_INET ],
# sidecar_program => $path_to_program,
);
my @hosts = qw( ipv6-test.com );
my $tcp = getprotobyname("tcp");
POE::Session->create(
inline_states => {
_start => sub {
foreach my $host (@hosts) {
$r->resolve(
host => $host,
service => "http",
event => "got_response",
hints => { protocol => $tcp },
) or die $!;
}
},
_stop => sub { print "client session stopped\n" },
got_response => sub {
my ($error, $addresses, $request) = @_[ARG0..ARG2];
use YAML; print YAML::Dump(
{
error => $error,
addr => $addresses,
req => $request,
}
);
},
}
);
POE::Kernel->run();
=head1 DESCRIPTION
POE::Component::Resolver performs Socket::getaddrinfo() calls in
subprocesses where they're permitted to block as long as necessary.
By default it will run eight subprocesses and prefer address families
in whatever order getaddrinfo() returns them. These defaults can be
overridden with constructor parameters. getaddrinfo() delegates to
the operating system's resolver, which may be reconfigured according
to the usual conventions.
=head2 PUBLIC METHODS
=head3 new
Create a new resolver. Returns an object that must be held and used
to make requests. See the synopsis.
Accepts up to four optional named parameters.
"af_order" may contain an arrayref with the address families to
permit, in the order in which they're preferred. Without "af_order",
the component will prefer IPv4 addresses over IPv6 for legacy
compatibility. This may change in the future as IPv6 gains more
widespread acceptance. See L</ENVIRONMENT VARIABLES> for a way to
override the default without hacking modules.
# Prefer IPv6 addresses, but also return IPv4 ones.
my $r1 = POE::Component::Resolver->new(
af_order => [ AF_INET6, AF_INET ]
);
# Only return IPv6 addresses,
# or nothing in cases where only IPv4 addresses exist.
my $r2 = POE::Component::Resolver->new(
af_order => [ AF_INET6 ]
);
"idle_timeout" determines how long to keep idle resolver subprocesses
before cleaning them up, in seconds. It defaults to 15.0 seconds.
"max_resolvers" controls the component's parallelism by defining the
maximum number of sidecar processes to manage. It defaults to 8, but
fewer or more processes can be configured depending on the resources
you have available and the amount of parallelism you require.
# One at a time, but without the pesky blocking.
my $r3 = POE::Component::Resolver->new( max_resolvers => 1 );
"sidecar_program" contains the disk location of a program that will
perform blocking lookups on standard input and print the results on
standard output. The sidecar program is needed only in special
environments where the bundling and execution of extra utilities is
tricky. PAR is one such environment.
The sidecar program needs to contain at least two statements:
use POE::Component::Resolver::Sidecar;
POE::Component::Resover::Sidecar->main();
=head3 resolve
resolve() begins a new request to resolve a domain. The request will
be enqueued in the component until a sidecar process can service it.
resolve() returns a request ID that may be used to cancel() a request
before it has completed (or undef if the request couldn't begin, such
as during shutdown). Resolve requires two parameters and accepts some
additional optional ones.
"host" and "service" are required and contain the host (name or
Internet address) and service (name or numeric port) that will be
passed verbatim to getaddrinfo(). See L<Socket> for details.
"event" is optional; it contains the name of the event that will
contain the resolver response. If omitted, it will default to
"resolver_response"; you may want to specify a shorter event name.
"hints" is optional. If specified, it must contain a hashref of hints
exactly as getaddrinfo() expects them. See L<Socket> for details.
"misc" is optional continuation data that will be passed back in the
response. It may contain any type of data the application requires.
=head3 cancel
Cancel a request, given the request's ID.
my $request_id = $resolver->resolve("poe.dyndns.org", "http");
$resolver->cancel($request_id);
=head3 shutdown
Shut down the resolver. POE::Component::Resolver retains resources
including child processes for up to "idle_timeout" seconds. This may
keep programs running up to "idle_timeout" seconds longer than they
should.
POE::Component::Resolver will release its resources (including child
processes) when its shutdown() method is called.
=head3 unpack_addr
In scalar context, unpack_addr($response_addr_hashref) returns the
addr element of $response_addr_hashref in a numeric form appropriate
for the address family of the address.
sub handle_resolver_response {
my ($error, $addresses, $request) = @_[ARG0..ARG2];
foreach my $a (@$addresses) {
my $numeric_addr = $resolver->unpack_addr($a);
print "$request->{host} = $numeric_addr\n";
}
}
In list context, it returns the numeric port and address.
sub handle_resolver_response {
my ($error, $addresses, $request) = @_[ARG0..ARG2];
foreach my $a (@$addresses) {
my ($$numeric_addr, $port) = $resolver->unpack_addr($a);
print "$request->{host} = $numeric_addr\n";
}
}
unpack_addr() is a convenience wrapper around getnameinfo() from
L<Socket>. You're certainly welcome to use the discrete function
instead.
unpack_addr() returns bleak emptiness on failure, regardless of
context. You can check for undef return.
=head2 PUBLIC EVENTS
=head3 resolver_response
The resolver response event includes three parameters.
$_[ARG0] and $_[ARG1] contain the retrn values from Socket's
getaddrinfo() call. These are an error message (if the call failed),
and an arrayref of address structures if the call succeeded.
The component provides its own error message, 'component shut down'.
This response is given for every pending request at the time the user
shuts down the component.
$_[ARG2] contains a hashref of information provided to the resolve()
method. Specifically, the values of resolve()'s "host", "service" and
"misc" parameters.
=head1 ENVIRONMENT VARIABLES
=head2 POCO_RESOLVER_IPV
The POCO_RESOLVER_IPV environment variable sets this component's
default Internet Protocol Version search order. If the variable
exists, it should contain a string with the numbers 4 and/or 6.
POE::Component::Resolver will treate these as Internet Protocol
versions to consider, in the order they are preferred.
POE::Component::Resolver's new() method accepts an "af_order"
parameter that overrides this environment variable.
Default to IPv4 addresses only:
export POCO_RESOLVER_IPV=4
Default to IPv6 addresses only:
export POCO_RESOLVER_IPV=6
Prefer IPv6, but accept IPv4 if needed:
export POCO_RESOLVER_IPV=64
Prefer IPv4, but accept IPv6 if needed:
export POCO_RESOLVER_IPV=46
=head1 COMPATIBILITY ISSUES
=head2 Microsoft Windows
This module requires "Microsoft TCP/IP version 6" to be installed.
Steps for Windows XP Pro (the steps for your particular version of
Windows may be subtly or drastically different):
=over
=item * Open your Control Panel
=item * Open your Network Connections
=item * Select your network connection from the available one(s)
=item * In the Local Area Connection Status dialog, click the Properties button
=item * If "Microsoft TCP/IP version 6" is listed as an item being used, you are done.
=item * Otherwise click Install...
=item * Choose to add a Protocol
=item * And install "Microsoft TCP/IP version 6" from the list of network protocols.
=back
=head1 BUGS
There is no timeout on requests.
There is no way to cancel a pending request.
=head1 TROUBLESHOOTING
=head2 programs linger for several seconds before exiting
Programs should shutdown() their POE::Component::Resolver objects when
they are through needing asynchronous DNS resolution. Programs should
additionally destroy their resolvers if they intend to run awhile and
want to reuse the memory they consume.
In some cases, it may be necessary to shutdown components that perform
asynchronous DNS using POE::Component::Resolver... such as
POE::Component::IRC, POE::Component::Client::Keepalive and
POE::Component::Client::HTTP.
By default, the resolver subprocesses hang around for idle_timeout,
which defaults to 15.0 seconds. Destroying the Resolver object will
clean up the process pool. Assuming only that is keeping the event
loop active, the program will then exit cleanly.
Alternatively, reduce idle_timeout to a more manageable number, such
as 5.0 seconds.
Otherwise something else may also be keeping the event loop active.
=head1 LICENSE
Except where otherwise noted, this distribution is Copyright 2011 by
Rocco Caputo. All rights reserved. This distribution is free
software; you may redistribute it and/or modify it under the same
terms as Perl itself.
=cut
|