--- AnyEvent/README 2013/12/17 16:43:15 1.72 +++ AnyEvent/README 2019/02/26 02:08:34 1.79 @@ -1,8 +1,9 @@ NAME AnyEvent - the DBI of event loop programming - EV, Event, Glib, Tk, Perl, Event::Lib, Irssi, rxvt-unicode, IO::Async, - Qt, FLTK and POE are various supported event loops/environments. + EV, Event, Glib, Tk, UV, Perl, Event::Lib, Irssi, rxvt-unicode, + IO::Async, Qt, FLTK and POE are various supported event + loops/environments. SYNOPSIS use AnyEvent; @@ -813,8 +814,8 @@ "croak" have been called. $cb = $cv->cb ($cb->($cv)) - This is a mutator function that returns the callback set and - optionally replaces it before doing so. + This is a mutator function that returns the callback set (or "undef" + if not) and optionally replaces it before doing so. The callback will be called when the condition becomes "true", i.e. when "send" or "croak" are called, with the only argument being the @@ -822,8 +823,13 @@ callback is called immediately when it is set. Calling "recv" inside the callback or at any later time is guaranteed not to block. + Additionally, when the callback is invoked, it is also removed from + the condvar (reset to "undef"), so the condvar does not keep a + reference to the callback after invocation. + SUPPORTED EVENT LOOPS/BACKENDS - The available backend classes are (every class has its own manpage): + The following backend classes are part of the AnyEvent distribution + (every class has its own manpage): Backends that are autoprobed when no other event loop can be found. EV is the preferred backend when no other event loop seems to be in @@ -845,6 +851,7 @@ AnyEvent::Impl::Event based on Event, very stable, few glitches. AnyEvent::Impl::Glib based on Glib, slow but very stable. AnyEvent::Impl::Tk based on Tk, very broken. + AnyEvent::Impl::UV based on UV, innovated square wheels. AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. AnyEvent::Impl::POE based on POE, very slow, some limitations. AnyEvent::Impl::Irssi used when running within irssi. @@ -877,6 +884,12 @@ load POE when detecting them, in the hope that POE will pick them up, in which case everything will be automatic. + Known event loops outside the AnyEvent distribution + The following event loops or programs support AnyEvent by providing + their own AnyEvent backend. They will be picked up automatically. + + urxvt::anyevent available to rxvt-unicode extensions + GLOBAL VARIABLES AND FUNCTIONS These are not normally required to use AnyEvent, but can be useful to write AnyEvent extension modules. @@ -910,13 +923,12 @@ model is autodetected (or immediately if that has already happened). The block will be executed *after* the actual backend has been - detected ($AnyEvent::MODEL is set), but *before* any watchers have - been created, so it is possible to e.g. patch @AnyEvent::ISA or do - other initialisations - see the sources of AnyEvent::Strict or - AnyEvent::AIO to see how this is used. + detected ($AnyEvent::MODEL is set), so it is possible to do some + initialisation only when AnyEvent is actually initialised - see the + sources of AnyEvent::AIO to see how this is used. The most common usage is to create some global watchers, without - forcing event module detection too early, for example, AnyEvent::AIO + forcing event module detection too early. For example, AnyEvent::AIO creates and installs the global IO::AIO watcher in a "post_detect" block to avoid autodetecting the event module at load time. @@ -942,9 +954,16 @@ $WATCHER ||= $guard; @AnyEvent::post_detect - If there are any code references in this array (you can "push" to it - before or after loading AnyEvent), then they will be called directly - after the event loop has been chosen. + This is a lower level interface then "AnyEvent::post_detect" (the + function). This variable is mainly useful for modules that can do + something useful when AnyEvent is used and thus want to know when it + is initialised, but do not need to even load it by default. This + array provides the means to hook into AnyEvent passively, without + loading it. + + Here is how it works: If there are any code references in this array + (you can "push" to it before or after loading AnyEvent), then they + will be called directly after the event loop has been chosen. You should check $AnyEvent::MODEL before adding to this array, though: if it is defined then the event loop has already been @@ -953,12 +972,6 @@ Best use "AnyEvent::post_detect { BLOCK }" when your application allows it, as it takes care of these details. - This variable is mainly useful for modules that can do something - useful when AnyEvent is used and thus want to know when it is - initialised, but do not need to even load it by default. This array - provides the means to hook into AnyEvent passively, without loading - it. - Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used together, you could put this into Coro (this is the actual code used by Coro to accomplish this): @@ -986,7 +999,7 @@ transaction object or guard to let you cancel the operation. For example, "AnyEvent::Socket::tcp_connect": - # start a conenction attempt unless one is active + # start a connection attempt unless one is active $self->{connect_guard} ||= AnyEvent::Socket::tcp_connect "www.example.net", 80, sub { delete $self->{connect_guard}; ... @@ -1030,6 +1043,10 @@ function, which can reduce typing, codesize and can reduce the logging overhead enourmously. + AnyEvent::fh_block $filehandle + AnyEvent::fh_unblock $filehandle + Sets blocking or non-blocking behaviour for the given filehandle. + WHAT TO DO IN A MODULE As a module author, you should "use AnyEvent" and call AnyEvent methods freely, but you should not load a specific event module or rely on it. @@ -1360,7 +1377,7 @@ This variable can effectively be used for denial-of-service attacks against local programs (e.g. when setuid), although the impact is - likely small, as the program has to handle conenction and other + likely small, as the program has to handle connection and other failures anyways. Examples: "PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6" - prefer IPv4 over @@ -1604,7 +1621,7 @@ ... }); - EV::loop; + EV::run; 3b. The module user could use AnyEvent, too: @@ -2121,12 +2138,13 @@ AnyEvent::Debug (interactive shell, watcher tracing). Supported event modules: AnyEvent::Loop, EV, EV::Glib, Glib::EV, Event, - Glib::Event, Glib, Tk, Event::Lib, Qt, POE, FLTK. + Glib::Event, Glib, Tk, Event::Lib, Qt, POE, FLTK, Cocoa::EventLoop, UV. Implementations: AnyEvent::Impl::EV, AnyEvent::Impl::Event, AnyEvent::Impl::Glib, AnyEvent::Impl::Tk, AnyEvent::Impl::Perl, AnyEvent::Impl::EventLib, AnyEvent::Impl::Qt, AnyEvent::Impl::POE, - AnyEvent::Impl::IOAsync, Anyevent::Impl::Irssi, AnyEvent::Impl::FLTK. + AnyEvent::Impl::IOAsync, AnyEvent::Impl::Irssi, AnyEvent::Impl::FLTK, + AnyEvent::Impl::Cocoa, AnyEvent::Impl::UV. Non-blocking handles, pipes, stream sockets, TCP clients and servers: AnyEvent::Handle, AnyEvent::Socket, AnyEvent::TLS.