1 | =head1 => NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | AnyEvent - provide framework for multiple event loops |
3 | AnyEvent - provide framework for multiple event loops |
4 | |
4 | |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops |
6 | |
6 | |
… | |
… | |
138 | Many watchers either are used with "recursion" (repeating timers for |
138 | Many watchers either are used with "recursion" (repeating timers for |
139 | example), or need to refer to their watcher object in other ways. |
139 | example), or need to refer to their watcher object in other ways. |
140 | |
140 | |
141 | An any way to achieve that is this pattern: |
141 | An any way to achieve that is this pattern: |
142 | |
142 | |
143 | my $w; $w = AnyEvent->type (arg => value ..., cb => sub { |
143 | my $w; $w = AnyEvent->type (arg => value ..., cb => sub { |
144 | # you can use $w here, for example to undef it |
144 | # you can use $w here, for example to undef it |
145 | undef $w; |
145 | undef $w; |
146 | }); |
146 | }); |
147 | |
147 | |
148 | Note that C<my $w; $w => combination. This is necessary because in Perl, |
148 | Note that C<my $w; $w => combination. This is necessary because in Perl, |
149 | my variables are only visible after the statement in which they are |
149 | my variables are only visible after the statement in which they are |
150 | declared. |
150 | declared. |
151 | |
151 | |
… | |
… | |
352 | AnyEvent program, you I<have> to create at least one watcher before you |
352 | AnyEvent program, you I<have> to create at least one watcher before you |
353 | C<fork> the child (alternatively, you can call C<AnyEvent::detect>). |
353 | C<fork> the child (alternatively, you can call C<AnyEvent::detect>). |
354 | |
354 | |
355 | Example: fork a process and wait for it |
355 | Example: fork a process and wait for it |
356 | |
356 | |
357 | my $done = AnyEvent->condvar; |
357 | my $done = AnyEvent->condvar; |
358 | |
358 | |
359 | my $pid = fork or exit 5; |
359 | my $pid = fork or exit 5; |
360 | |
360 | |
361 | my $w = AnyEvent->child ( |
361 | my $w = AnyEvent->child ( |
362 | pid => $pid, |
362 | pid => $pid, |
363 | cb => sub { |
363 | cb => sub { |
364 | my ($pid, $status) = @_; |
364 | my ($pid, $status) = @_; |
365 | warn "pid $pid exited with status $status"; |
365 | warn "pid $pid exited with status $status"; |
366 | $done->send; |
366 | $done->send; |
367 | }, |
367 | }, |
368 | ); |
368 | ); |
369 | |
369 | |
370 | # do something else, then wait for process exit |
370 | # do something else, then wait for process exit |
371 | $done->recv; |
371 | $done->recv; |
372 | |
372 | |
373 | =head2 CONDITION VARIABLES |
373 | =head2 CONDITION VARIABLES |
374 | |
374 | |
375 | If you are familiar with some event loops you will know that all of them |
375 | If you are familiar with some event loops you will know that all of them |
376 | require you to run some blocking "loop", "run" or similar function that |
376 | require you to run some blocking "loop", "run" or similar function that |
… | |
… | |
752 | |
752 | |
753 | =item L<AnyEvent::DNS> |
753 | =item L<AnyEvent::DNS> |
754 | |
754 | |
755 | Provides rich asynchronous DNS resolver capabilities. |
755 | Provides rich asynchronous DNS resolver capabilities. |
756 | |
756 | |
|
|
757 | =item L<AnyEvent::HTTP> |
|
|
758 | |
|
|
759 | A simple-to-use HTTP library that is capable of making a lot of concurrent |
|
|
760 | HTTP requests. |
|
|
761 | |
757 | =item L<AnyEvent::HTTPD> |
762 | =item L<AnyEvent::HTTPD> |
758 | |
763 | |
759 | Provides a simple web application server framework. |
764 | Provides a simple web application server framework. |
760 | |
765 | |
761 | =item L<AnyEvent::FastPing> |
766 | =item L<AnyEvent::FastPing> |
… | |
… | |
807 | no warnings; |
812 | no warnings; |
808 | use strict; |
813 | use strict; |
809 | |
814 | |
810 | use Carp; |
815 | use Carp; |
811 | |
816 | |
812 | our $VERSION = 4.11; |
817 | our $VERSION = 4.15; |
813 | our $MODEL; |
818 | our $MODEL; |
814 | |
819 | |
815 | our $AUTOLOAD; |
820 | our $AUTOLOAD; |
816 | our @ISA; |
821 | our @ISA; |
817 | |
822 | |
… | |
… | |
1173 | This functionality might change in future versions. |
1178 | This functionality might change in future versions. |
1174 | |
1179 | |
1175 | For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you |
1180 | For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you |
1176 | could start your program like this: |
1181 | could start your program like this: |
1177 | |
1182 | |
1178 | PERL_ANYEVENT_MODEL=Perl perl ... |
1183 | PERL_ANYEVENT_MODEL=Perl perl ... |
1179 | |
1184 | |
1180 | =item C<PERL_ANYEVENT_PROTOCOLS> |
1185 | =item C<PERL_ANYEVENT_PROTOCOLS> |
1181 | |
1186 | |
1182 | Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences |
1187 | Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences |
1183 | for IPv4 or IPv6. The default is unspecified (and might change, or be the result |
1188 | for IPv4 or IPv6. The default is unspecified (and might change, or be the result |
… | |
… | |
1658 | specified in the variable. |
1663 | specified in the variable. |
1659 | |
1664 | |
1660 | You can make AnyEvent completely ignore this variable by deleting it |
1665 | You can make AnyEvent completely ignore this variable by deleting it |
1661 | before the first watcher gets created, e.g. with a C<BEGIN> block: |
1666 | before the first watcher gets created, e.g. with a C<BEGIN> block: |
1662 | |
1667 | |
1663 | BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } |
1668 | BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } |
1664 | |
1669 | |
1665 | use AnyEvent; |
1670 | use AnyEvent; |
1666 | |
1671 | |
1667 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1672 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1668 | be used to probe what backend is used and gain other information (which is |
1673 | be used to probe what backend is used and gain other information (which is |
1669 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
1674 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
|
|
1675 | |
|
|
1676 | |
|
|
1677 | =head1 BUGS |
|
|
1678 | |
|
|
1679 | Perl 5.8 has numerous memleaks that sometimes hit this module and are hard |
|
|
1680 | to work around. If you suffer from memleaks, first upgrade to Perl 5.10 |
|
|
1681 | and check wether the leaks still show up. (Perl 5.10.0 has other annoying |
|
|
1682 | mamleaks, such as leaking on C<map> and C<grep> but it is usually not as |
|
|
1683 | pronounced). |
1670 | |
1684 | |
1671 | |
1685 | |
1672 | =head1 SEE ALSO |
1686 | =head1 SEE ALSO |
1673 | |
1687 | |
1674 | Utility functions: L<AnyEvent::Util>. |
1688 | Utility functions: L<AnyEvent::Util>. |
… | |
… | |
1691 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. |
1705 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. |
1692 | |
1706 | |
1693 | |
1707 | |
1694 | =head1 AUTHOR |
1708 | =head1 AUTHOR |
1695 | |
1709 | |
1696 | Marc Lehmann <schmorp@schmorp.de> |
1710 | Marc Lehmann <schmorp@schmorp.de> |
1697 | http://home.schmorp.de/ |
1711 | http://home.schmorp.de/ |
1698 | |
1712 | |
1699 | =cut |
1713 | =cut |
1700 | |
1714 | |
1701 | 1 |
1715 | 1 |
1702 | |
1716 | |