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 | |
… | |
… | |
17 | }); |
17 | }); |
18 | |
18 | |
19 | my $w = AnyEvent->condvar; # stores whether a condition was flagged |
19 | my $w = AnyEvent->condvar; # stores whether a condition was flagged |
20 | $w->send; # wake up current and all future recv's |
20 | $w->send; # wake up current and all future recv's |
21 | $w->recv; # enters "main loop" till $condvar gets ->send |
21 | $w->recv; # enters "main loop" till $condvar gets ->send |
|
|
22 | |
|
|
23 | =head1 INTRODUCTION/TUTORIAL |
|
|
24 | |
|
|
25 | This manpage is mainly a reference manual. If you are interested |
|
|
26 | in a tutorial or some gentle introduction, have a look at the |
|
|
27 | L<AnyEvent::Intro> manpage. |
22 | |
28 | |
23 | =head1 WHY YOU SHOULD USE THIS MODULE (OR NOT) |
29 | =head1 WHY YOU SHOULD USE THIS MODULE (OR NOT) |
24 | |
30 | |
25 | Glib, POE, IO::Async, Event... CPAN offers event models by the dozen |
31 | Glib, POE, IO::Async, Event... CPAN offers event models by the dozen |
26 | nowadays. So what is different about AnyEvent? |
32 | nowadays. So what is different about AnyEvent? |
… | |
… | |
132 | Many watchers either are used with "recursion" (repeating timers for |
138 | Many watchers either are used with "recursion" (repeating timers for |
133 | 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. |
134 | |
140 | |
135 | An any way to achieve that is this pattern: |
141 | An any way to achieve that is this pattern: |
136 | |
142 | |
137 | my $w; $w = AnyEvent->type (arg => value ..., cb => sub { |
143 | my $w; $w = AnyEvent->type (arg => value ..., cb => sub { |
138 | # you can use $w here, for example to undef it |
144 | # you can use $w here, for example to undef it |
139 | undef $w; |
145 | undef $w; |
140 | }); |
146 | }); |
141 | |
147 | |
142 | 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, |
143 | 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 |
144 | declared. |
150 | declared. |
145 | |
151 | |
… | |
… | |
346 | 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 |
347 | C<fork> the child (alternatively, you can call C<AnyEvent::detect>). |
353 | C<fork> the child (alternatively, you can call C<AnyEvent::detect>). |
348 | |
354 | |
349 | Example: fork a process and wait for it |
355 | Example: fork a process and wait for it |
350 | |
356 | |
351 | my $done = AnyEvent->condvar; |
357 | my $done = AnyEvent->condvar; |
352 | |
358 | |
353 | my $pid = fork or exit 5; |
359 | my $pid = fork or exit 5; |
354 | |
360 | |
355 | my $w = AnyEvent->child ( |
361 | my $w = AnyEvent->child ( |
356 | pid => $pid, |
362 | pid => $pid, |
357 | cb => sub { |
363 | cb => sub { |
358 | my ($pid, $status) = @_; |
364 | my ($pid, $status) = @_; |
359 | warn "pid $pid exited with status $status"; |
365 | warn "pid $pid exited with status $status"; |
360 | $done->send; |
366 | $done->send; |
361 | }, |
367 | }, |
362 | ); |
368 | ); |
363 | |
369 | |
364 | # do something else, then wait for process exit |
370 | # do something else, then wait for process exit |
365 | $done->recv; |
371 | $done->recv; |
366 | |
372 | |
367 | =head2 CONDITION VARIABLES |
373 | =head2 CONDITION VARIABLES |
368 | |
374 | |
369 | 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 |
370 | 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 |
… | |
… | |
591 | |
597 | |
592 | This is a mutator function that returns the callback set and optionally |
598 | This is a mutator function that returns the callback set and optionally |
593 | replaces it before doing so. |
599 | replaces it before doing so. |
594 | |
600 | |
595 | The callback will be called when the condition becomes "true", i.e. when |
601 | The callback will be called when the condition becomes "true", i.e. when |
596 | C<send> or C<croak> are called. Calling C<recv> inside the callback |
602 | C<send> or C<croak> are called, with the only argument being the condition |
597 | or at any later time is guaranteed not to block. |
603 | variable itself. Calling C<recv> inside the callback or at any later time |
|
|
604 | is guaranteed not to block. |
598 | |
605 | |
599 | =back |
606 | =back |
600 | |
607 | |
601 | =head1 GLOBAL VARIABLES AND FUNCTIONS |
608 | =head1 GLOBAL VARIABLES AND FUNCTIONS |
602 | |
609 | |
… | |
… | |
745 | |
752 | |
746 | =item L<AnyEvent::DNS> |
753 | =item L<AnyEvent::DNS> |
747 | |
754 | |
748 | Provides rich asynchronous DNS resolver capabilities. |
755 | Provides rich asynchronous DNS resolver capabilities. |
749 | |
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 | |
750 | =item L<AnyEvent::HTTPD> |
762 | =item L<AnyEvent::HTTPD> |
751 | |
763 | |
752 | Provides a simple web application server framework. |
764 | Provides a simple web application server framework. |
753 | |
765 | |
754 | =item L<AnyEvent::FastPing> |
766 | =item L<AnyEvent::FastPing> |
755 | |
767 | |
756 | The fastest ping in the west. |
768 | The fastest ping in the west. |
|
|
769 | |
|
|
770 | =item L<AnyEvent::DBI> |
|
|
771 | |
|
|
772 | Executes DBI requests asynchronously in a proxy process. |
757 | |
773 | |
758 | =item L<Net::IRC3> |
774 | =item L<Net::IRC3> |
759 | |
775 | |
760 | AnyEvent based IRC client module family. |
776 | AnyEvent based IRC client module family. |
761 | |
777 | |
… | |
… | |
800 | no warnings; |
816 | no warnings; |
801 | use strict; |
817 | use strict; |
802 | |
818 | |
803 | use Carp; |
819 | use Carp; |
804 | |
820 | |
805 | our $VERSION = '4.1'; |
821 | our $VERSION = 4.160; |
806 | our $MODEL; |
822 | our $MODEL; |
807 | |
823 | |
808 | our $AUTOLOAD; |
824 | our $AUTOLOAD; |
809 | our @ISA; |
825 | our @ISA; |
810 | |
826 | |
… | |
… | |
972 | sub AnyEvent::Base::Signal::DESTROY { |
988 | sub AnyEvent::Base::Signal::DESTROY { |
973 | my ($signal, $cb) = @{$_[0]}; |
989 | my ($signal, $cb) = @{$_[0]}; |
974 | |
990 | |
975 | delete $SIG_CB{$signal}{$cb}; |
991 | delete $SIG_CB{$signal}{$cb}; |
976 | |
992 | |
977 | $SIG{$signal} = 'DEFAULT' unless keys %{ $SIG_CB{$signal} }; |
993 | delete $SIG{$signal} unless keys %{ $SIG_CB{$signal} }; |
978 | } |
994 | } |
979 | |
995 | |
980 | # default implementation for ->child |
996 | # default implementation for ->child |
981 | |
997 | |
982 | our %PID_CB; |
998 | our %PID_CB; |
… | |
… | |
1166 | This functionality might change in future versions. |
1182 | This functionality might change in future versions. |
1167 | |
1183 | |
1168 | For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you |
1184 | For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you |
1169 | could start your program like this: |
1185 | could start your program like this: |
1170 | |
1186 | |
1171 | PERL_ANYEVENT_MODEL=Perl perl ... |
1187 | PERL_ANYEVENT_MODEL=Perl perl ... |
1172 | |
1188 | |
1173 | =item C<PERL_ANYEVENT_PROTOCOLS> |
1189 | =item C<PERL_ANYEVENT_PROTOCOLS> |
1174 | |
1190 | |
1175 | Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences |
1191 | Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences |
1176 | for IPv4 or IPv6. The default is unspecified (and might change, or be the result |
1192 | for IPv4 or IPv6. The default is unspecified (and might change, or be the result |
… | |
… | |
1651 | specified in the variable. |
1667 | specified in the variable. |
1652 | |
1668 | |
1653 | You can make AnyEvent completely ignore this variable by deleting it |
1669 | You can make AnyEvent completely ignore this variable by deleting it |
1654 | before the first watcher gets created, e.g. with a C<BEGIN> block: |
1670 | before the first watcher gets created, e.g. with a C<BEGIN> block: |
1655 | |
1671 | |
1656 | BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } |
1672 | BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } |
1657 | |
1673 | |
1658 | use AnyEvent; |
1674 | use AnyEvent; |
1659 | |
1675 | |
1660 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1676 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1661 | be used to probe what backend is used and gain other information (which is |
1677 | be used to probe what backend is used and gain other information (which is |
1662 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
1678 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
|
|
1679 | |
|
|
1680 | |
|
|
1681 | =head1 BUGS |
|
|
1682 | |
|
|
1683 | Perl 5.8 has numerous memleaks that sometimes hit this module and are hard |
|
|
1684 | to work around. If you suffer from memleaks, first upgrade to Perl 5.10 |
|
|
1685 | and check wether the leaks still show up. (Perl 5.10.0 has other annoying |
|
|
1686 | mamleaks, such as leaking on C<map> and C<grep> but it is usually not as |
|
|
1687 | pronounced). |
1663 | |
1688 | |
1664 | |
1689 | |
1665 | =head1 SEE ALSO |
1690 | =head1 SEE ALSO |
1666 | |
1691 | |
1667 | Utility functions: L<AnyEvent::Util>. |
1692 | Utility functions: L<AnyEvent::Util>. |
… | |
… | |
1684 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. |
1709 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. |
1685 | |
1710 | |
1686 | |
1711 | |
1687 | =head1 AUTHOR |
1712 | =head1 AUTHOR |
1688 | |
1713 | |
1689 | Marc Lehmann <schmorp@schmorp.de> |
1714 | Marc Lehmann <schmorp@schmorp.de> |
1690 | http://home.schmorp.de/ |
1715 | http://home.schmorp.de/ |
1691 | |
1716 | |
1692 | =cut |
1717 | =cut |
1693 | |
1718 | |
1694 | 1 |
1719 | 1 |
1695 | |
1720 | |