--- EV/EV.pm 2007/12/20 07:12:57 1.72 +++ EV/EV.pm 2007/12/21 05:10:01 1.73 @@ -90,6 +90,47 @@ @EV::Loop::Default::ISA = "EV::Loop"; +=head1 EVENT LOOPS + +EV supports multiple event loops: There is a single "default event loop" +that can handle everything including signals and child watchers, and any +number of "dynamic event loops" that can use different backends (with +various limitations), but no child and signal watchers. + +You do not have to do anything to create the default event loop: When +the module is loaded a suitable backend is selected on the premise of +selecting a working backend (which for example rules out kqueue on most +BSDs). Modules should, unless they have "special needs" always use the +default loop as this is fastest (perl-wise), best supported by other +modules (e.g. AnyEvent or Coro) and most portable event loop. + +For specific programs you cna create additional event loops dynamically. + +=over 4 + +=item $loop = new EV::loop [$flags] + +Create a new event loop as per the specified flags. Please refer to the +C function description in the libev documentation +(L) +for more info. + +The loop will automatically be destroyed when it is no longer referenced +by any watcher and the loop object goes out of scope. + +Using C is recommended, as only the default event loop +is protected by this module. + +=item $loop->loop_fork + +Must be called after a fork in the child, before entering or continuing +the event loop. An alternative is to use C which calls +this fucntion automatically, at some performance loss (refer to the libev +documentation). + +=back + + =head1 BASIC INTERFACE =over 4 @@ -108,17 +149,23 @@ =item $time = EV::now +=item $time = $loop->now + Returns the time the last event loop iteration has been started. This is the time that (relative) timers are based on, and refering to it is usually faster then calling EV::time. -=item $method = EV::method +=item $backend = EV::backend + +=item $backend = $loop->backend Returns an integer describing the backend used by libev (EV::METHOD_SELECT or EV::METHOD_EPOLL). =item EV::loop [$flags] +=item $loop->loop ([$flags]) + Begin checking for events and calling callbacks. It returns when a callback calls EV::unloop. @@ -130,6 +177,8 @@ =item EV::unloop [$how] +=item $loop->unloop ([$how]) + When called with no arguments or an argument of EV::UNLOOP_ONE, makes the innermost call to EV::loop return. @@ -138,11 +187,15 @@ =item $count = EV::loop_count +=item $count = $loop->loop_count + Return the number of times the event loop has polled for new events. Sometiems useful as a generation counter. =item EV::once $fh_or_undef, $events, $timeout, $cb->($revents) +=item $loop->once ($fh_or_undef, $events, $timeout, $cb->($revents)) + This function rolls together an I/O and a timer watcher for a single one-shot event without the need for managing a watcher object. @@ -166,6 +219,8 @@ =item EV::feed_fd_event ($fd, $revents) +=item $loop->feed_fd_event ($fd, $revents) + Feed an event on a file descriptor into EV. EV will react to this call as if the readyness notifications specified by C<$revents> (a combination of C and C) happened on the file descriptor C<$fd>. @@ -178,7 +233,7 @@ =back -=head2 WATCHER OBJECTS +=head1 WATCHER OBJECTS A watcher is an object that gets created to record your interest in some event. For instance, if you want to wait for STDIN to become readable, you @@ -315,7 +370,7 @@ =back -=head2 WATCHER TYPES +=head1 WATCHER TYPES Each of the following subsections describes a single watcher type. @@ -327,6 +382,10 @@ =item $w = EV::io_ns $fileno_or_fh, $eventmask, $callback +=item $w = $loop->io 8$fileno_or_fh, $eventmask, $callback) + +=item $w = $loop->io_ns ($fileno_or_fh, $eventmask, $callback) + As long as the returned watcher object is alive, call the C<$callback> when at least one of events specified in C<$eventmask> occurs. @@ -365,6 +424,10 @@ =item $w = EV::timer_ns $after, $repeat, $callback +=item $w = $loop->timer ($after, $repeat, $callback) + +=item $w = $loop->timer_ns ($after, $repeat, $callback) + Calls the callback after C<$after> seconds (which may be fractional). If C<$repeat> is non-zero, the timer will be restarted (with the $repeat value as $after) after the callback returns. @@ -415,6 +478,10 @@ =item $w = EV::periodic_ns $at, $interval, $reschedule_cb, $callback +=item $w = $loop->periodic ($at, $interval, $reschedule_cb, $callback) + +=item $w = $loop->periodic_ns ($at, $interval, $reschedule_cb, $callback) + Similar to EV::timer, but is not based on relative timeouts but on absolute times. Apart from creating "simple" timers that trigger "at" the specified time, it can also be used for non-drifting absolute timers and @@ -548,6 +615,10 @@ =item $w = EV::child_ns $pid, $callback +=item $w = $loop->child ($pid, $callback) + +=item $w = $loop->child_ns ($pid, $callback) + Call the callback when a status change for pid C<$pid> (or any pid if C<$pid> is 0) has been received. More precisely: when the process receives a C, EV will fetch the outstanding exit/wait status for all @@ -598,6 +669,10 @@ =item $w = EV::stat_ns $path, $interval, $callback +=item $w = $loop->stat ($path, $interval, $callback) + +=item $w = $loop->stat_ns ($path, $interval, $callback) + Call the callback when a file status change has been detected on C<$path>. The C<$path> does not need to exist, changing from "path exists" to "path does not exist" is a status change like any other. @@ -677,6 +752,10 @@ =item $w = EV::idle_ns $callback +=item $w = $loop->idle ($callback) + +=item $w = $loop->idle_ns ($callback) + Call the callback when there are no other pending watchers of the same or higher priority (excluding check, prepare and other idle watchers of the same or lower priority, of course). They are called idle watchers because @@ -708,6 +787,10 @@ =item $w = EV::prepare_ns $callback +=item $w = $loop->prepare ($callback) + +=item $w = $loop->prepare_ns 8$callback) + Call the callback just before the process would block. You can still create/modify any watchers at this point. @@ -726,6 +809,10 @@ =item $w = EV::check_ns $callback +=item $w = $loop->check ($callback) + +=item $w = $loop->check_ns ($callback) + Call the callback just after the process wakes up again (after it has gathered events), but before any other callbacks have been invoked. @@ -789,6 +876,10 @@ =item $w = EV::fork_ns $callback +=item $w = $loop->fork ($callback) + +=item $w = $loop->fork_ns ($callback) + Call the callback before the event loop is resumed in the child process after a fork. @@ -852,8 +943,9 @@ =head1 SEE ALSO -L (asynchronous dns), L (makes Glib/Gtk2 use EV as -event loop), L (efficient coroutines with EV). +L (asynchronous DNS), L (makes Glib/Gtk2 use EV as +event loop), L (embed Glib into EV), L (efficient +coroutines with EV), L (asynchronous SNMP). =head1 AUTHOR