--- AnyEvent/lib/AnyEvent.pm 2008/05/29 03:45:37 1.145 +++ AnyEvent/lib/AnyEvent.pm 2008/07/08 19:50:25 1.164 @@ -1,4 +1,4 @@ -=head1 => NAME +=head1 NAME AnyEvent - provide framework for multiple event loops @@ -20,6 +20,12 @@ $w->send; # wake up current and all future recv's $w->recv; # enters "main loop" till $condvar gets ->send +=head1 INTRODUCTION/TUTORIAL + +This manpage is mainly a reference manual. If you are interested +in a tutorial or some gentle introduction, have a look at the +L manpage. + =head1 WHY YOU SHOULD USE THIS MODULE (OR NOT) Glib, POE, IO::Async, Event... CPAN offers event models by the dozen @@ -134,10 +140,10 @@ An any way to achieve that is this pattern: - my $w; $w = AnyEvent->type (arg => value ..., cb => sub { - # you can use $w here, for example to undef it - undef $w; - }); + my $w; $w = AnyEvent->type (arg => value ..., cb => sub { + # you can use $w here, for example to undef it + undef $w; + }); Note that C combination. This is necessary because in Perl, my variables are only visible after the statement in which they are @@ -166,9 +172,9 @@ always use non-blocking calls when reading/writing from/to your file handles. -Example: +Example: wait for readability of STDIN, then read a line and disable the +watcher. - # wait for readability of STDIN, then read a line and disable the watcher my $w; $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub { chomp (my $input = ); warn "read: $input\n"; @@ -188,13 +194,17 @@ presence is undefined and you cannot rely on them. Portable AnyEvent callbacks cannot use arguments passed to time watcher callbacks. -The timer callback will be invoked at most once: if you want a repeating -timer you have to create a new watcher (this is a limitation by both Tk -and Glib). +The callback will normally be invoked once only. If you specify another +parameter, C, as a positive number, then the callback will be +invoked regularly at that interval (in fractional seconds) after the first +invocation. + +The callback will be rescheduled before invoking the callback, but no +attempt is done to avoid timer drift in most backends, so the interval is +only approximate. -Example: +Example: fire an event after 7.7 seconds. - # fire an event after 7.7 seconds my $w = AnyEvent->timer (after => 7.7, cb => sub { warn "timeout\n"; }); @@ -202,19 +212,12 @@ # to cancel the timer: undef $w; -Example 2: - - # fire an event after 0.5 seconds, then roughly every second - my $w; +Example 2: fire an event after 0.5 seconds, then roughly every second. - my $cb = sub { - # cancel the old timer while creating a new one - $w = AnyEvent->timer (after => 1, cb => $cb); + my $w = AnyEvent->timer (after => 0.5, interval => 1, cb => sub { + warn "timeout\n"; }; - # start the "loop" by creating the first watcher - $w = AnyEvent->timer (after => 0.5, cb => $cb); - =head3 TIMING ISSUES There are two ways to handle timers: based on real time (relative, "fire @@ -348,21 +351,21 @@ Example: fork a process and wait for it - my $done = AnyEvent->condvar; - - my $pid = fork or exit 5; - - my $w = AnyEvent->child ( - pid => $pid, - cb => sub { - my ($pid, $status) = @_; - warn "pid $pid exited with status $status"; - $done->send; - }, - ); - - # do something else, then wait for process exit - $done->recv; + my $done = AnyEvent->condvar; + + my $pid = fork or exit 5; + + my $w = AnyEvent->child ( + pid => $pid, + cb => sub { + my ($pid, $status) = @_; + warn "pid $pid exited with status $status"; + $done->send; + }, + ); + + # do something else, then wait for process exit + $done->recv; =head2 CONDITION VARIABLES @@ -593,8 +596,9 @@ replaces it before doing so. The callback will be called when the condition becomes "true", i.e. when -C or C are called. Calling C inside the callback -or at any later time is guaranteed not to block. +C or C are called, with the only argument being the condition +variable itself. Calling C inside the callback or at any later time +is guaranteed not to block. =back @@ -733,20 +737,27 @@ Contains various utility functions that replace often-used but blocking functions such as C by event-/callback-based versions. -=item L - -Provide read and write buffers and manages watchers for reads and writes. - =item L Provides various utility functions for (internet protocol) sockets, addresses and name resolution. Also functions to create non-blocking tcp connections or tcp servers, with IPv6 and SRV record support and more. +=item L + +Provide read and write buffers, manages watchers for reads and writes, +supports raw and formatted I/O, I/O queued and fully transparent and +non-blocking SSL/TLS. + =item L Provides rich asynchronous DNS resolver capabilities. +=item L + +A simple-to-use HTTP library that is capable of making a lot of concurrent +HTTP requests. + =item L Provides a simple web application server framework. @@ -755,6 +766,30 @@ The fastest ping in the west. +=item L + +Executes L requests asynchronously in a proxy process. + +=item L + +Truly asynchronous I/O, should be in the toolbox of every event +programmer. AnyEvent::AIO transparently fuses L and AnyEvent +together. + +=item L + +Truly asynchronous Berkeley DB access. AnyEvent::BDB transparently fuses +L and AnyEvent together. + +=item L + +A non-blocking interface to gpsd, a daemon delivering GPS information. + +=item L + +A non-blocking interface to the Internet Go Server protocol (used by +L). + =item L AnyEvent based IRC client module family. @@ -776,17 +811,6 @@ Has special support for AnyEvent via L. -=item L, L - -Truly asynchronous I/O, should be in the toolbox of every event -programmer. AnyEvent::AIO transparently fuses IO::AIO and AnyEvent -together. - -=item L, L - -Truly asynchronous Berkeley DB access. AnyEvent::AIO transparently fuses -IO::AIO and AnyEvent together. - =item L The lambda approach to I/O - don't ask, look there. Can use AnyEvent. @@ -802,7 +826,7 @@ use Carp; -our $VERSION = '4.1'; +our $VERSION = 4.2; our $MODEL; our $AUTOLOAD; @@ -974,7 +998,7 @@ delete $SIG_CB{$signal}{$cb}; - $SIG{$signal} = 'DEFAULT' unless keys %{ $SIG_CB{$signal} }; + delete $SIG{$signal} unless keys %{ $SIG_CB{$signal} }; } # default implementation for ->child @@ -1168,7 +1192,7 @@ For example, to force the pure perl model (L) you could start your program like this: - PERL_ANYEVENT_MODEL=Perl perl ... + PERL_ANYEVENT_MODEL=Perl perl ... =item C @@ -1653,15 +1677,24 @@ You can make AnyEvent completely ignore this variable by deleting it before the first watcher gets created, e.g. with a C block: - BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } - - use AnyEvent; + BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } + + use AnyEvent; Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can be used to probe what backend is used and gain other information (which is probably even less useful to an attacker than PERL_ANYEVENT_MODEL). +=head1 BUGS + +Perl 5.8 has numerous memleaks that sometimes hit this module and are hard +to work around. If you suffer from memleaks, first upgrade to Perl 5.10 +and check wether the leaks still show up. (Perl 5.10.0 has other annoying +mamleaks, such as leaking on C and C but it is usually not as +pronounced). + + =head1 SEE ALSO Utility functions: L. @@ -1686,8 +1719,8 @@ =head1 AUTHOR - Marc Lehmann - http://home.schmorp.de/ + Marc Lehmann + http://home.schmorp.de/ =cut