=head1 DESCRIPTION
+The newest version of this document is also available as a html-formatted
+web page you might find easier to navigate when reading it for the first
+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
these event sources and provide your program with events.
Change the callback. You can change the callback at virtually any time
(modulo threads).
+=item ev_set_priority (ev_TYPE *watcher, priority)
+
+=item int ev_priority (ev_TYPE *watcher)
+
+Set and query the priority of the watcher. The priority is a small
+integer between C<EV_MAXPRI> (default: C<2>) and C<EV_MINPRI>
+(default: C<-2>). Pending watchers with higher priority will be invoked
+before watchers with lower priority, but priority will not keep watchers
+from being executed (except for C<ev_idle> watchers).
+
+This means that priorities are I<only> used for ordering callback
+invocation after new events have been received. This is useful, for
+example, to reduce latency after idling, or more often, to bind two
+watchers on the same event and make sure one is called first.
+
+If you need to suppress invocation when higher priority events are pending
+you need to look at C<ev_idle> watchers, which provide this functionality.
+
+The default priority used by watchers when no priority has been set is
+always C<0>, which is supposed to not be too high and not be too low :).
+
+Setting a priority outside the range of C<EV_MINPRI> to C<EV_MAXPRI> is
+fine, as long as you do not mind that the priority value you query might
+or might not have been adjusted to be within valid range.
+
=back
If you cannot run the fd in non-blocking mode (for example you should not
play around with an Xlib connection), then you have to seperately re-test
-wether a file descriptor is really ready with a known-to-be good interface
+whether a file descriptor is really ready with a known-to-be good interface
such as poll (fortunately in our Xlib example, Xlib already does this on
its own, so its quite safe to use).
=head2 C<ev_idle> - when you've got nothing better to do...
-Idle watchers trigger events when there are no other events are pending
-(prepare, check and other idle watchers do not count). That is, as long
-as your process is busy handling sockets or timeouts (or even signals,
-imagine) it will not be triggered. But when your process is idle all idle
-watchers are being called again and again, once per event loop iteration -
-until stopped, that is, or your process receives more events and becomes
-busy.
+Idle watchers trigger events when no other events of the same or higher
+priority are pending (prepare, check and other idle watchers do not
+count).
+
+That is, as long as your process is busy handling sockets or timeouts
+(or even signals, imagine) of the same or higher priority it will not be
+triggered. But when your process is idle (or only lower-priority watchers
+are pending), the idle watchers are being called once per event loop
+iteration - until stopped, that is, or your process receives more events
+and becomes busy again with higher priority stuff.
The most noteworthy effect is that as long as any idle watchers are
active, the process will not block when waiting for new events.
=head1 MACRO MAGIC
Libev can be compiled with a variety of options, the most fundemantal is
-C<EV_MULTIPLICITY>. This option determines wether (most) functions and
+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
=back
Example: Declare and initialise a check watcher, utilising the above
-macros so it will work regardless of wether multiple loops are supported
+macros so it will work regardless of whether multiple loops are supported
or not.
static void
for multiple event loops and there is no first event loop pointer
argument. Instead, all functions act on the single default loop.
+=item EV_MINPRI
+
+=item EV_MAXPRI
+
+The range of allowed priorities. C<EV_MINPRI> must be smaller or equal to
+C<EV_MAXPRI>, but otherwise there are no non-obvious limitations. You can
+provide for more priorities by overriding those symbols (usually defined
+to be C<-2> and C<2>, respectively).
+
+When doing priority-based operations, libev usually has to linearly search
+all the priorities, so having many of them (hundreds) uses a lot of space
+and time, so using the defaults of five priorities (-2 .. +2) is usually
+fine.
+
+If your embedding app does not need any priorities, defining these both to
+C<0> will save some memory and cpu.
+
=item EV_PERIODIC_ENABLE
If undefined or defined to be C<1>, then periodic timers are supported. If
defined to be C<0>, then they are not. Disabling them saves a few kB of
code.
+=item EV_IDLE_ENABLE
+
+If undefined or defined to be C<1>, then idle watchers are supported. If
+defined to be C<0>, then they are not. Disabling them saves a few kB of
+code.
+
=item EV_EMBED_ENABLE
If undefined or defined to be C<1>, then embed watchers are supported. If
=item Starting and stopping timer/periodic watchers: O(log skipped_other_timers)
+This means that, when you have a watcher that triggers in one hour and
+there are 100 watchers that would trigger before that then inserting will
+have to skip those 100 watchers.
+
=item Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)
+That means that for changing a timer costs less than removing/adding them
+as only the relative motion in the event queue has to be paid for.
+
=item Starting io/check/prepare/idle/signal/child watchers: O(1)
+These just add the watcher into an array or at the head of a list. If
+the array needs to be extended libev needs to realloc and move the whole
+array, but this happen asymptotically less and less with more watchers,
+thus amortised O(1).
+
=item Stopping check/prepare/idle watchers: O(1)
=item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))
+These watchers are stored in lists then need to be walked to find the
+correct watcher to remove. The lists are usually short (you don't usually
+have many watchers waiting for the same fd or signal).
+
=item Finding the next timer per loop iteration: O(1)
=item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)
+A change means an I/O watcher gets started or stopped, which requires
+libev to recalculate its status (and possibly tell the kernel).
+
=item Activating one watcher: O(1)
+=item Priority handling: O(number_of_priorities)
+
+Priorities are implemented by allocating some space for each
+priority. When doing priority-based operations, libev usually has to
+linearly search all the priorities.
+
=back