| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Socket::More::Resolver::AE - Resolver AnyEvent integration | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | use AnyEvent; | ||
| 8 | |||
| 9 | use Socket::More::Resolver; | ||
| 10 | |||
| 11 | ... | ||
| 12 | |||
| 13 | getaddrinfo... | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | Built in driver for integrating L<Socket::More::Resolver> into L<AnyEvent>. | ||
| 18 | |||
| 19 | If the event loop module is already in memory, it should automatically be | ||
| 20 | detected when using L<Socket::More::Resolver>; | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | use warnings; | ||
| 25 | use strict; | ||
| 26 | package Socket::More::Resolver::AE; | ||
| 27 | |||
| 28 | # Circular reference to lexical scope variable. | ||
| 29 | my $circle=[]; | ||
| 30 | my $_timer; | ||
| 31 | my @watchers; | ||
| 32 | push @$circle, $circle, \$_timer, \@watchers; | ||
| 33 | |||
| 34 | |||
| 35 | # Return true value (code ref) on require | ||
| 36 | # NOTE | ||
| 37 | sub { | ||
| 38 | # Code here to set up event handling on $loop that may be required | ||
| 39 | my @fh=Socket::More::Resolver::to_watch; | ||
| 40 | for(@fh){ | ||
| 41 | #my $fh=$_; | ||
| 42 | my $in_fd=fileno $_; | ||
| 43 | my $w= AE::io $in_fd, 0, sub { | ||
| 44 | Socket::More::Resolver::process_results $in_fd; | ||
| 45 | }; | ||
| 46 | push @watchers, $w; | ||
| 47 | } | ||
| 48 | $Socket::More::Resolver::Shared=1; | ||
| 49 | #setup timer to monitor child existance | ||
| 50 | $_timer=AE::timer 0, 1, \&Socket::More::Resolver::monitor_workers; | ||
| 51 | |||
| 52 | } | ||
| 53 |