1 | => NAME |
1 | NAME |
2 | AnyEvent - provide framework for multiple event loops |
2 | AnyEvent - provide framework for multiple event loops |
3 | |
3 | |
4 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event |
4 | EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event |
5 | loops |
5 | loops |
6 | |
6 | |
… | |
… | |
16 | }); |
16 | }); |
17 | |
17 | |
18 | my $w = AnyEvent->condvar; # stores whether a condition was flagged |
18 | my $w = AnyEvent->condvar; # stores whether a condition was flagged |
19 | $w->send; # wake up current and all future recv's |
19 | $w->send; # wake up current and all future recv's |
20 | $w->recv; # enters "main loop" till $condvar gets ->send |
20 | $w->recv; # enters "main loop" till $condvar gets ->send |
|
|
21 | |
|
|
22 | INTRODUCTION/TUTORIAL |
|
|
23 | This manpage is mainly a reference manual. If you are interested in a |
|
|
24 | tutorial or some gentle introduction, have a look at the AnyEvent::Intro |
|
|
25 | manpage. |
21 | |
26 | |
22 | WHY YOU SHOULD USE THIS MODULE (OR NOT) |
27 | WHY YOU SHOULD USE THIS MODULE (OR NOT) |
23 | Glib, POE, IO::Async, Event... CPAN offers event models by the dozen |
28 | Glib, POE, IO::Async, Event... CPAN offers event models by the dozen |
24 | nowadays. So what is different about AnyEvent? |
29 | nowadays. So what is different about AnyEvent? |
25 | |
30 | |
… | |
… | |
128 | Many watchers either are used with "recursion" (repeating timers for |
133 | Many watchers either are used with "recursion" (repeating timers for |
129 | example), or need to refer to their watcher object in other ways. |
134 | example), or need to refer to their watcher object in other ways. |
130 | |
135 | |
131 | An any way to achieve that is this pattern: |
136 | An any way to achieve that is this pattern: |
132 | |
137 | |
133 | my $w; $w = AnyEvent->type (arg => value ..., cb => sub { |
138 | my $w; $w = AnyEvent->type (arg => value ..., cb => sub { |
134 | # you can use $w here, for example to undef it |
139 | # you can use $w here, for example to undef it |
135 | undef $w; |
140 | undef $w; |
136 | }); |
141 | }); |
137 | |
142 | |
138 | Note that "my $w; $w =" combination. This is necessary because in Perl, |
143 | Note that "my $w; $w =" combination. This is necessary because in Perl, |
139 | my variables are only visible after the statement in which they are |
144 | my variables are only visible after the statement in which they are |
140 | declared. |
145 | declared. |
141 | |
146 | |
… | |
… | |
337 | an AnyEvent program, you *have* to create at least one watcher before |
342 | an AnyEvent program, you *have* to create at least one watcher before |
338 | you "fork" the child (alternatively, you can call "AnyEvent::detect"). |
343 | you "fork" the child (alternatively, you can call "AnyEvent::detect"). |
339 | |
344 | |
340 | Example: fork a process and wait for it |
345 | Example: fork a process and wait for it |
341 | |
346 | |
342 | my $done = AnyEvent->condvar; |
347 | my $done = AnyEvent->condvar; |
343 | |
348 | |
344 | my $pid = fork or exit 5; |
349 | my $pid = fork or exit 5; |
345 | |
350 | |
346 | my $w = AnyEvent->child ( |
351 | my $w = AnyEvent->child ( |
347 | pid => $pid, |
352 | pid => $pid, |
348 | cb => sub { |
353 | cb => sub { |
349 | my ($pid, $status) = @_; |
354 | my ($pid, $status) = @_; |
350 | warn "pid $pid exited with status $status"; |
355 | warn "pid $pid exited with status $status"; |
351 | $done->send; |
356 | $done->send; |
352 | }, |
357 | }, |
353 | ); |
358 | ); |
354 | |
359 | |
355 | # do something else, then wait for process exit |
360 | # do something else, then wait for process exit |
356 | $done->recv; |
361 | $done->recv; |
357 | |
362 | |
358 | CONDITION VARIABLES |
363 | CONDITION VARIABLES |
359 | If you are familiar with some event loops you will know that all of them |
364 | If you are familiar with some event loops you will know that all of them |
360 | require you to run some blocking "loop", "run" or similar function that |
365 | require you to run some blocking "loop", "run" or similar function that |
361 | will actively watch for new events and call your callbacks. |
366 | will actively watch for new events and call your callbacks. |
… | |
… | |
567 | $cb = $cv->cb ([new callback]) |
572 | $cb = $cv->cb ([new callback]) |
568 | This is a mutator function that returns the callback set and |
573 | This is a mutator function that returns the callback set and |
569 | optionally replaces it before doing so. |
574 | optionally replaces it before doing so. |
570 | |
575 | |
571 | The callback will be called when the condition becomes "true", i.e. |
576 | The callback will be called when the condition becomes "true", i.e. |
572 | when "send" or "croak" are called. Calling "recv" inside the |
577 | when "send" or "croak" are called, with the only argument being the |
|
|
578 | condition variable itself. Calling "recv" inside the callback or at |
573 | callback or at any later time is guaranteed not to block. |
579 | any later time is guaranteed not to block. |
574 | |
580 | |
575 | GLOBAL VARIABLES AND FUNCTIONS |
581 | GLOBAL VARIABLES AND FUNCTIONS |
576 | $AnyEvent::MODEL |
582 | $AnyEvent::MODEL |
577 | Contains "undef" until the first watcher is being created. Then it |
583 | Contains "undef" until the first watcher is being created. Then it |
578 | contains the event model that is being used, which is the name of |
584 | contains the event model that is being used, which is the name of |
… | |
… | |
705 | more. |
711 | more. |
706 | |
712 | |
707 | AnyEvent::DNS |
713 | AnyEvent::DNS |
708 | Provides rich asynchronous DNS resolver capabilities. |
714 | Provides rich asynchronous DNS resolver capabilities. |
709 | |
715 | |
|
|
716 | AnyEvent::HTTP |
|
|
717 | A simple-to-use HTTP library that is capable of making a lot of |
|
|
718 | concurrent HTTP requests. |
|
|
719 | |
710 | AnyEvent::HTTPD |
720 | AnyEvent::HTTPD |
711 | Provides a simple web application server framework. |
721 | Provides a simple web application server framework. |
712 | |
722 | |
713 | AnyEvent::FastPing |
723 | AnyEvent::FastPing |
714 | The fastest ping in the west. |
724 | The fastest ping in the west. |
|
|
725 | |
|
|
726 | AnyEvent::DBI |
|
|
727 | Executes DBI requests asynchronously in a proxy process. |
715 | |
728 | |
716 | Net::IRC3 |
729 | Net::IRC3 |
717 | AnyEvent based IRC client module family. |
730 | AnyEvent based IRC client module family. |
718 | |
731 | |
719 | Net::XMPP2 |
732 | Net::XMPP2 |
… | |
… | |
811 | This functionality might change in future versions. |
824 | This functionality might change in future versions. |
812 | |
825 | |
813 | For example, to force the pure perl model (AnyEvent::Impl::Perl) you |
826 | For example, to force the pure perl model (AnyEvent::Impl::Perl) you |
814 | could start your program like this: |
827 | could start your program like this: |
815 | |
828 | |
816 | PERL_ANYEVENT_MODEL=Perl perl ... |
829 | PERL_ANYEVENT_MODEL=Perl perl ... |
817 | |
830 | |
818 | "PERL_ANYEVENT_PROTOCOLS" |
831 | "PERL_ANYEVENT_PROTOCOLS" |
819 | Used by both AnyEvent::DNS and AnyEvent::Socket to determine |
832 | Used by both AnyEvent::DNS and AnyEvent::Socket to determine |
820 | preferences for IPv4 or IPv6. The default is unspecified (and might |
833 | preferences for IPv4 or IPv6. The default is unspecified (and might |
821 | change, or be the result of auto probing). |
834 | change, or be the result of auto probing). |
… | |
… | |
1262 | model than specified in the variable. |
1275 | model than specified in the variable. |
1263 | |
1276 | |
1264 | You can make AnyEvent completely ignore this variable by deleting it |
1277 | You can make AnyEvent completely ignore this variable by deleting it |
1265 | before the first watcher gets created, e.g. with a "BEGIN" block: |
1278 | before the first watcher gets created, e.g. with a "BEGIN" block: |
1266 | |
1279 | |
1267 | BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } |
1280 | BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } |
1268 | |
1281 | |
1269 | use AnyEvent; |
1282 | use AnyEvent; |
1270 | |
1283 | |
1271 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1284 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1272 | be used to probe what backend is used and gain other information (which |
1285 | be used to probe what backend is used and gain other information (which |
1273 | is probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
1286 | is probably even less useful to an attacker than PERL_ANYEVENT_MODEL). |
1274 | |
1287 | |
|
|
1288 | BUGS |
|
|
1289 | Perl 5.8 has numerous memleaks that sometimes hit this module and are |
|
|
1290 | hard to work around. If you suffer from memleaks, first upgrade to Perl |
|
|
1291 | 5.10 and check wether the leaks still show up. (Perl 5.10.0 has other |
|
|
1292 | annoying mamleaks, such as leaking on "map" and "grep" but it is usually |
|
|
1293 | not as pronounced). |
|
|
1294 | |
1275 | SEE ALSO |
1295 | SEE ALSO |
1276 | Utility functions: AnyEvent::Util. |
1296 | Utility functions: AnyEvent::Util. |
1277 | |
1297 | |
1278 | Event modules: EV, EV::Glib, Glib::EV, Event, Glib::Event, Glib, Tk, |
1298 | Event modules: EV, EV::Glib, Glib::EV, Event, Glib::Event, Glib, Tk, |
1279 | Event::Lib, Qt, POE. |
1299 | Event::Lib, Qt, POE. |
… | |
… | |
1290 | Coroutine support: Coro, Coro::AnyEvent, Coro::EV, Coro::Event, |
1310 | Coroutine support: Coro, Coro::AnyEvent, Coro::EV, Coro::Event, |
1291 | |
1311 | |
1292 | Nontrivial usage examples: Net::FCP, Net::XMPP2, AnyEvent::DNS. |
1312 | Nontrivial usage examples: Net::FCP, Net::XMPP2, AnyEvent::DNS. |
1293 | |
1313 | |
1294 | AUTHOR |
1314 | AUTHOR |
1295 | Marc Lehmann <schmorp@schmorp.de> |
1315 | Marc Lehmann <schmorp@schmorp.de> |
1296 | http://home.schmorp.de/ |
1316 | http://home.schmorp.de/ |
1297 | |
1317 | |