time: L<http://cvs.schmorp.de/libev/ev.html>.
Libev is an event loop: you register interest in certain events (such as a
-file descriptor being readable or a timeout occuring), and it will manage
+file descriptor being readable or a timeout occurring), and it will manage
these event sources and provide your program with events.
To do this, it must take more or less complete control over your process
the beginning of 1970, details are complicated, don't ask). This type is
called C<ev_tstamp>, which is what you should use too. It usually aliases
to the C<double> type in C, and when you need to do any calculations on
-it, you should treat it as such.
+it, you should treat it as some floatingpoint value. Unlike the name
+component C<stamp> might indicate, it is also used for time differences
+throughout libev.
=head1 GLOBAL FUNCTIONS
Kqueue deserves special mention, as at the time of this writing, it
was broken on all BSDs except NetBSD (usually it doesn't work with
-anything but sockets and pipes, except on Darwin, where of course its
-completely useless). For this reason its not being "autodetected"
+anything but sockets and pipes, except on Darwin, where of course it's
+completely useless). For this reason it's not being "autodetected"
unless you explicitly specify it explicitly in the flags (i.e. using
C<EVBACKEND_KQUEUE>).
sense, so e.g. C<ev_is_active> might still return true. It is your
responsibility to either stop all watchers cleanly yoursef I<before>
calling this function, or cope with the fact afterwards (which is usually
-the easiest thing, youc na just ignore the watchers and/or C<free ()> them
+the easiest thing, you can just ignore the watchers and/or C<free ()> them
for example).
+Note that certain global state, such as signal state, will not be freed by
+this function, and related watchers (such as signal and child watchers)
+would need to be stopped manually.
+
+In general it is not advisable to call this function except in the
+rare occasion where you really need to free e.g. the signal handling
+pipe fds. If you need dynamically allocated loops it is better to use
+C<ev_loop_new> and C<ev_loop_destroy>).
+
=item ev_loop_destroy (loop)
Like C<ev_default_destroy>, but destroys an event loop created by an
received events and started processing them. This timestamp does not
change as long as callbacks are being processed, and this is also the base
time used for relative timers. You can treat it as the timestamp of the
-event occuring (or more correctly, libev finding out about it).
+event occurring (or more correctly, libev finding out about it).
=item ev_loop (loop, int flags)
such as poll (fortunately in our Xlib example, Xlib already does this on
its own, so its quite safe to use).
+=head3 The special problem of disappearing file descriptors
+
+Some backends (e.g kqueue, epoll) need to be told about closing a file
+descriptor (either by calling C<close> explicitly or by any other means,
+such as C<dup>). The reason is that you register interest in some file
+descriptor, but when it goes away, the operating system will silently drop
+this interest. If another file descriptor with the same number then is
+registered with libev, there is no efficient way to see that this is, in
+fact, a different file descriptor.
+
+To avoid having to explicitly tell libev about such cases, libev follows
+the following policy: Each time C<ev_io_set> is being called, libev
+will assume that this is potentially a new file descriptor, otherwise
+it is assumed that the file descriptor stays the same. That means that
+you I<have> to call C<ev_io_set> (or C<ev_io_init>) when you change the
+descriptor even if the file descriptor number itself did not change.
+
+This is how one would do it normally anyway, the important point is that
+the libev application should not optimise around libev but should leave
+optimisations to libev.
+
+
+=head3 Watcher-Specific Functions
+
=over 4
=item ev_io_init (ev_io *, callback, int fd, int events)
but if multiple timers become ready during the same loop iteration then
order of execution is undefined.
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)
time (C<at>) has been passed, but if multiple periodic timers become ready
during the same loop iteration then order of execution is undefined.
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb)
switched off. Can be changed any time, but changes only take effect when
the periodic timer fires or C<ev_periodic_again> is being called.
+=item ev_tstamp at [read-only]
+
+When active, contains the absolute time that the watcher is supposed to
+trigger next.
+
=back
Example: Call a callback every hour, or, more precisely, whenever the
watcher for a signal is stopped libev will reset the signal handler to
SIG_DFL (regardless of what it was set to before).
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_signal_init (ev_signal *, callback, int signum)
Child watchers trigger when your process receives a SIGCHLD in response to
some child status changes (most typically when a child of yours dies).
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_child_init (ev_child *, callback, int pid)
usually detected immediately, and if the file exists there will be no
polling.
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)
"pseudo-background processing", or delay processing stuff to after the
event loop has handled all outstanding events.
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_idle_init (ev_signal *, callback)
C<ev_check> watcher ran (always remind yourself to coexist peacefully with
others).
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_prepare_init (ev_prepare *, callback)
else
loop_lo = loop_hi;
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)
similarly to C<ev_loop (embedded_loop, EVLOOP_NONBLOCK)>, but in the most
apropriate way for embedded loops.
-=item struct ev_loop *loop [read-only]
+=item struct ev_loop *other [read-only]
The embedded event loop.
C<ev_default_fork> cheats and calls it in the wrong process, the fork
handlers will be invoked, too, of course.
+=head3 Watcher-Specific Functions and Data Members
+
=over 4
=item ev_fork_init (ev_signal *, callback)
Stops the watcher if it is active. Again, no C<loop> argument.
-=item w->again () C<ev::timer>, C<ev::periodic> only
+=item w->again () (C<ev::timer>, C<ev::periodic> only)
For C<ev::timer> and C<ev::periodic>, this invokes the corresponding
C<ev_TYPE_again> function.
-=item w->sweep () C<ev::embed> only
+=item w->sweep () (C<ev::embed> only)
Invokes C<ev_embed_sweep>.
-=item w->update () C<ev::stat> only
+=item w->update () (C<ev::stat> only)
Invokes C<ev_stat_stat>.
=head1 MACRO MAGIC
-Libev can be compiled with a variety of options, the most fundemantal is
-C<EV_MULTIPLICITY>. This option determines whether (most) functions and
-callbacks have an initial C<struct ev_loop *> argument.
+Libev can be compiled with a variety of options, the most fundamantal
+of which is C<EV_MULTIPLICITY>. This option determines whether (most)
+functions and callbacks have an initial C<struct ev_loop *> argument.
To make it easier to write programs that cope with either variant, the
following macros are defined:
Game Server, the EV perl module, the GNU Virtual Private Ethernet (gvpe)
and rxvt-unicode.
-The goal is to enable you to just copy the neecssary files into your
+The goal is to enable you to just copy the necessary files into your
source directory without having to change even a single line in them, so
you can easily upgrade by simply copying (or having a checked-out copy of
libev somewhere in your source tree).
monotonic clock option at both compiletime and runtime. Otherwise no use
of the monotonic clock option will be attempted. If you enable this, you
usually have to link against librt or something similar. Enabling it when
-the functionality isn't available is safe, though, althoguh you have
+the functionality isn't available is safe, though, although you have
to make sure you link against any libraries where the C<clock_gettime>
function is hiding in (often F<-lrt>).
realtime clock option at compiletime (and assume its availability at
runtime if successful). Otherwise no use of the realtime clock option will
be attempted. This effectively replaces C<gettimeofday> by C<clock_get
-(CLOCK_REALTIME, ...)> and will not normally affect correctness. See tzhe note about libraries
-in the description of C<EV_USE_MONOTONIC>, though.
+(CLOCK_REALTIME, ...)> and will not normally affect correctness. See the
+note about libraries in the description of C<EV_USE_MONOTONIC>, though.
=item EV_USE_SELECT
Can be used to change the callback member declaration in each watcher,
and the way callbacks are invoked and set. Must expand to a struct member
-definition and a statement, respectively. See the F<ev.v> header file for
+definition and a statement, respectively. See the F<ev.h> header file for
their default definitions. One possible use for overriding these is to
avoid the C<struct ev_loop *> as first argument in all cases, or to use
method calls instead of plain function calls in C++.
+=head2 EXPORTED API SYMBOLS
+
+If you need to re-export the API (e.g. via a dll) and you need a list of
+exported symbols, you can use the provided F<Symbol.*> files which list
+all public symbols, one per line:
+
+ Symbols.ev for libev proper
+ Symbols.event for the libevent emulation
+
+This can also be used to rename all public symbols to avoid clashes with
+multiple versions of libev linked together (which is obviously bad in
+itself, but sometimes it is inconvinient to avoid this).
+
+A sed command like this will create wrapper C<#define>'s that you need to
+include before including F<ev.h>:
+
+ <Symbols.ev sed -e "s/.*/#define & myprefix_&/" >wrap.h
+
+This would create a file F<wrap.h> which essentially looks like this:
+
+ #define ev_backend myprefix_ev_backend
+ #define ev_check_start myprefix_ev_check_start
+ #define ev_check_stop myprefix_ev_check_stop
+ ...
+
=head2 EXAMPLES
For a real-world example of a program the includes libev