--- AnyEvent/README 2008/06/22 12:17:47 1.27 +++ AnyEvent/README 2008/07/12 20:45:27 1.28 @@ -32,11 +32,12 @@ policy* and AnyEvent is *small and efficient*. First and foremost, *AnyEvent is not an event model* itself, it only - interfaces to whatever event model the main program happens to use in a + interfaces to whatever event model the main program happens to use, in a pragmatic way. For event models and certain classes of immortals alike, the statement "there can only be one" is a bitter reality: In general, only one event loop can be active at the same time in a process. - AnyEvent helps hiding the differences between those event loops. + AnyEvent cannot change this, but it can hide the differences between + those event loops. The goal of AnyEvent is to offer module authors the ability to do event programming (waiting for I/O or timer events) without subscribing to a @@ -47,8 +48,8 @@ For modules like POE or IO::Async (which is a total misnomer as it is actually doing all I/O *synchronously*...), using them in your module is like joining a cult: After you joined, you are dependent on them and you - cannot use anything else, as it is simply incompatible to everything - that isn't itself. What's worse, all the potential users of your module + cannot use anything else, as they are simply incompatible to everything + that isn't them. What's worse, all the potential users of your module are *also* forced to use the same event loop you use. AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works @@ -56,9 +57,9 @@ with the rest: POE + IO::Async? No go. Tk + Event? No go. Again: if your module uses one of those, every user of your module has to use it, too. But if your module uses AnyEvent, it works transparently with all event - models it supports (including stuff like POE and IO::Async, as long as - those use one of the supported event loops. It is trivial to add new - event loops to AnyEvent, too, so it is future-proof). + models it supports (including stuff like IO::Async, as long as those use + one of the supported event loops. It is trivial to add new event loops + to AnyEvent, too, so it is future-proof). In addition to being free of having to use *the one and only true event model*, AnyEvent also is free of bloat and policy: with POE or similar @@ -148,7 +149,8 @@ You can create an I/O watcher by calling the "AnyEvent->io" method with the following mandatory key-value pairs as arguments: - "fh" the Perl *file handle* (*not* file descriptor) to watch for events. + "fh" the Perl *file handle* (*not* file descriptor) to watch for events + (AnyEvent might or might not keep a reference to this file handle). "poll" must be a string that is either "r" or "w", which creates a watcher waiting for "r"eadable or "w"ritable events, respectively. "cb" is the callback to invoke each time the file handle becomes ready. @@ -165,9 +167,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"; @@ -186,13 +188,18 @@ 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, "interval", as a strictly positive number (> 0), then the + callback will be invoked regularly at that interval (in fractional + seconds) after the first invocation. If "interval" is specified with a + false value, then it is treated as if it were missing. + + 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"; }); @@ -200,19 +207,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); - TIMING ISSUES There are two ways to handle timers: based on real time (relative, "fire in 10 seconds") and based on wallclock time (absolute, "fire at 12 @@ -297,8 +297,8 @@ SIGNAL WATCHERS You can watch for signals using a signal watcher, "signal" is the signal - *name* without any "SIG" prefix, "cb" is the Perl callback to be invoked - whenever a signal occurs. + *name* in uppercase and without any "SIG" prefix, "cb" is the Perl + callback to be invoked whenever a signal occurs. Although the callback might get passed parameters, their value and presence is undefined and you cannot rely on them. Portable AnyEvent @@ -700,16 +700,17 @@ blocking functions such as "inet_aton" by event-/callback-based versions. - AnyEvent::Handle - Provide read and write buffers and manages watchers for reads and - writes. - AnyEvent::Socket 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. + AnyEvent::Handle + 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. + AnyEvent::DNS Provides rich asynchronous DNS resolver capabilities. @@ -726,6 +727,23 @@ AnyEvent::DBI Executes DBI requests asynchronously in a proxy process. + AnyEvent::AIO + Truly asynchronous I/O, should be in the toolbox of every event + programmer. AnyEvent::AIO transparently fuses IO::AIO and AnyEvent + together. + + AnyEvent::BDB + Truly asynchronous Berkeley DB access. AnyEvent::BDB transparently + fuses BDB and AnyEvent together. + + AnyEvent::GPSD + A non-blocking interface to gpsd, a daemon delivering GPS + information. + + AnyEvent::IGS + A non-blocking interface to the Internet Go Server protocol (used by + App::IGS). + Net::IRC3 AnyEvent based IRC client module family. @@ -742,15 +760,6 @@ Coro Has special support for AnyEvent via Coro::AnyEvent. - AnyEvent::AIO, IO::AIO - Truly asynchronous I/O, should be in the toolbox of every event - programmer. AnyEvent::AIO transparently fuses IO::AIO and AnyEvent - together. - - AnyEvent::BDB, BDB - Truly asynchronous Berkeley DB access. AnyEvent::AIO transparently - fuses IO::AIO and AnyEvent together. - IO::Lambda The lambda approach to I/O - don't ask, look there. Can use AnyEvent. @@ -813,6 +822,18 @@ When set to 2 or higher, cause AnyEvent to report to STDERR which event model it chooses. + "PERL_ANYEVENT_STRICT" + AnyEvent does not do much argument checking by default, as thorough + argument checking is very costly. Setting this variable to a true + value will cause AnyEvent to load "AnyEvent::Strict" and then to + thoroughly check the arguments passed to most method calls. If it + finds any problems it will croak. + + In other words, enables "strict" mode. + + Unlike "use strict" it is definitely recommended ot keep it off in + production. + "PERL_ANYEVENT_MODEL" This can be used to specify the event model to be used by AnyEvent, before auto detection and -probing kicks in. It must be a string @@ -1283,7 +1304,8 @@ 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). + is probably even less useful to an attacker than PERL_ANYEVENT_MODEL), + and $ENV{PERL_ANYEGENT_STRICT}. BUGS Perl 5.8 has numerous memleaks that sometimes hit this module and are