X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/09c28a9820828432b5ced0a8f2b05c56213690fc..363b337b90b2575d2cc5253af2ffe6afa0d3eb72:/ev.html diff --git a/ev.html b/ev.html index 1dcdd21..21f24d5 100644 --- a/ev.html +++ b/ev.html @@ -6,7 +6,7 @@ - +
@@ -29,7 +29,10 @@ev_io
- is this file descriptor readable or writable?ev_io
- is this file descriptor readable or writable?
+
+ev_timer
- relative and optionally repeating timeoutsev_periodic
- to cron or not to cron?ev_signal
- signal me when a signal gets signalled!You can find out the major and minor version numbers of the library +
You can find out the major and minor ABI version numbers of the library
you linked against by calling the functions ev_version_major
and
ev_version_minor
. If you want, you can compare against the global
symbols EV_VERSION_MAJOR
and EV_VERSION_MINOR
, which specify the
version of the library your program was compiled against.
These version numbers refer to the ABI version of the library, not the +release version.
Usually, it's a good idea to terminate if the major versions mismatch, -as this indicates an incompatible change. Minor versions are usually +as this indicates an incompatible change. Minor versions are usually compatible to older versions, so a larger minor version alone is usually not a problem.
Example: Make sure we haven't accidentally been linked against the wrong
@@ -531,8 +536,9 @@ external event in conjunction with something not expressible using other
libev watchers. However, a pair of ev_prepare
/ev_check
watchers is
usually a better approach for this kind of thing.
Here are the gory details of what ev_loop
does:
* If there are no active watchers (reference count is zero), return. - - Queue prepare watchers and then call all outstanding watchers. +- Before the first iteration, call any pending watchers. + * If there are no active watchers (reference count is zero), return. + - Queue all prepare watchers and then call all outstanding watchers. - If we have been forked, recreate the kernel state. - Update the kernel state with all outstanding changes. - Update the "event loop time". @@ -940,6 +946,30 @@ play around with an Xlib connection), then you have to seperately re-test 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). + + +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
+close
explicitly or by any other means, +such asdup
). 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
+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 have to callev_io_set
(orev_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.
+ + + +
- ev_io_init (ev_io *, callback, int fd, int events)
- ev_io_set (ev_io *, int fd, int events)
@@ -1098,10 +1128,10 @@ to trigger "at" some specific point in time. For example, if you tell periodic watcher to trigger in 10 seconds (by specifiying e.g.ev_now () + 10.
) and then reset your system clock to the last year, then it will take a year to trigger the event (unlike anev_timer
, which would trigger -roughly 10 seconds later and of course not if you reset your system time -again). +roughly 10 seconds later).They can also be used to implement vastly more complex timers, such as -triggering an event on eahc midnight, local time.
+triggering an event on each midnight, local time or other, complicated, +rules.As with timers, the callback is guarenteed to be invoked only when the time (
@@ -1113,18 +1143,18 @@ during the same loop iteration then order of execution is undefined. operation, and we will explain them from simplest to complex:at
) has been passed, but if multiple periodic timers become ready during the same loop iteration then order of execution is undefined.
-
- * absolute timer (interval = reschedule_cb = 0)
+- * absolute timer (at = time, interval = reschedule_cb = 0)
- -
In this configuration the watcher triggers an event at the wallclock time
at
and doesn't repeat. It will not adjust when a time jump occurs, that is, if it is to be run at January 1st 2011 then it will run when the system time reaches or surpasses this time.- * non-repeating interval timer (interval > 0, reschedule_cb = 0)
+- * non-repeating interval timer (at = offset, interval > 0, reschedule_cb = 0)
- -
In this mode the watcher will always be scheduled to time out at the next -
+at + N * interval
time (for some integer N) and then repeat, regardless -of any time jumps.at + N * interval
time (for some integer N, which can also be negative) +and then repeat, regardless of any time jumps.This can be used to create timers that do not drift with respect to system time:
ev_periodic_set (&periodic, 0., 3600., 0); @@ -1137,8 +1167,11 @@ by 3600.Another way to think about it (for the mathematically inclined) is that
+ev_periodic
will try to run the callback in this mode at the next possible time wheretime = at (mod interval)
, regardless of any time jumps.For numerical stability it is preferable that the
at
value is near +ev_now ()
(the current time), but there is no range requirement for +this value.- * manual reschedule mode (reschedule_cb = callback)
+- * manual reschedule mode (at and interval ignored, reschedule_cb = callback)
- +
In this mode the values for
interval
andat
are both being ignored. Instead, each time the periodic watcher gets scheduled, the @@ -1147,7 +1180,7 @@ current time as second argument.NOTE: This callback MUST NOT stop or destroy any periodic watcher, ever, or make any event loop modifications. If you need to stop it, return
+starting annow + 1e30
(or so, fudge fudge) and stop it afterwards (e.g. by -starting a prepare watcher).ev_prepare
watcher, which is legal).Its prototype is
ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now)
, e.g.:static ev_tstamp my_rescheduler (struct ev_periodic *w, ev_tstamp now) @@ -1177,6 +1210,13 @@ reason I omitted it as an example). when you changed some parameters or the reschedule callback would return a different time than the last time it was called (e.g. in a crond like program when the crontabs have changed). +- ev_tstamp offset [read-write]
+- +
When repeating, this contains the offset value, otherwise this is the +absolute point in time (the
+at
value passed toev_periodic_set
).Can be modified any time, but changes only take effect when the periodic +timer fires or
ev_periodic_again
is being called.- ev_tstamp interval [read-write]
- @@ -1485,6 +1525,15 @@ with priority higher than or equal to the event loop and one coroutine of lower priority, but only once, using idle watchers to keep the event loop from blocking if lower-priority coroutines are active, thus mapping low-priority coroutines to idle/background tasks). +
It is recommended to give
ev_check
watchers highest (EV_MAXPRI
) +priority, to ensure that they are being run before any other watchers +after the poll. Also,ev_check
watchers (andev_prepare
watchers, +too) should not activate ("feed") events into libev. While libev fully +supports this, they will be called before otherev_check
watchers did +their job. Asev_check
watchers are often used to embed other event +loops those other event loops might be in an unusable state until their +ev_check
watcher ran (always remind yourself to coexist peacefully with +others).
- ev_prepare_init (ev_prepare *, callback)
- ev_check_init (ev_check *, callback)