X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/924ae10c0376cdb4b581d30f7b8a258b6b9e4853..71217f48ea498d7292ca3bf17b8bffe1ab97e642:/ev.html diff --git a/ev.html b/ev.html index bb85c18..ec6eb1b 100644 --- a/ev.html +++ b/ev.html @@ -6,7 +6,7 @@ - + @@ -743,7 +743,7 @@ is pending (but not active) you must not call an init function on it (but ev_TYPE_set is safe) and you must make sure the watcher is available to libev (e.g. you cnanot free () it).

-
callback = ev_cb (ev_TYPE *watcher)
+
callback ev_cb (ev_TYPE *watcher)

Returns the callback currently set on the watcher.

@@ -785,13 +785,41 @@ can cast it back to your own type:

} -

More interesting and less C-conformant ways of catsing your callback type -have been omitted....

+

More interesting and less C-conformant ways of casting your callback type +instead have been omitted.

+

Another common scenario is having some data structure with multiple +watchers:

+
  struct my_biggy
+  {
+    int some_data;
+    ev_timer t1;
+    ev_timer t2;
+  }
 
+
+

In this case getting the pointer to my_biggy is a bit more complicated, +you need to use offsetof:

+
  #include <stddef.h>
 
+  static void
+  t1_cb (EV_P_ struct ev_timer *w, int revents)
+  {
+    struct my_biggy big = (struct my_biggy *
+      (((char *)w) - offsetof (struct my_biggy, t1));
+  }
 
+  static void
+  t2_cb (EV_P_ struct ev_timer *w, int revents)
+  {
+    struct my_biggy big = (struct my_biggy *
+      (((char *)w) - offsetof (struct my_biggy, t2));
+  }
 
 
+
+
+
+

WATCHER TYPES

@@ -1221,7 +1249,7 @@ not exist" is signified by the st_nlink field being zero (whic otherwise always forced to be at least one) and all the other fields of the stat buffer having unspecified contents.

Since there is no standard to do this, the portable implementation simply -calls stat (2) regulalry on the path to see if it changed somehow. You +calls stat (2) regularly on the path to see if it changed somehow. You can specify a recommended polling interval for this case. If you specify a polling interval of 0 (highly recommended!) then a suitable, unspecified default value will be used (which you can expect to be around @@ -1231,8 +1259,13 @@ usually overkill.

This watcher type is not meant for massive numbers of stat watchers, as even with OS-supported change notifications, this can be resource-intensive.

-

At the time of this writing, no specific OS backends are implemented, but -if demand increases, at least a kqueue and inotify backend will be added.

+

At the time of this writing, only the Linux inotify interface is +implemented (implementing kqueue support is left as an exercise for the +reader). Inotify will be used to give hints only and should not change the +semantics of ev_stat watchers, which means that libev sometimes needs +to fall back to regular polling again even with inotify, but changes are +usually detected immediately, and if the file exists there will be no +polling.

ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)
ev_stat_set (ev_stat *, const char *path, ev_tstamp interval)
@@ -1989,6 +2022,12 @@ backend for Solaris 10 systems.

reserved for future expansion, works like the USE symbols above.

+
EV_USE_INOTIFY
+
+

If defined to be 1, libev will compile in support for the Linux inotify +interface to speed up ev_stat watchers. Its actual availability will +be detected at runtime.

+
EV_H

The name of the ev.h header file used to include it. The default if @@ -2053,7 +2092,15 @@ some inlining decisions, saves roughly 30% codesize of amd64.

ev_child watchers use a small hash table to distribute workload by pid. The default size is 16 (or 1 with EV_MINIMAL), usually more than enough. If you need to manage thousands of children you might want to -increase this value.

+increase this value (must be a power of two).

+
+
EV_INOTIFY_HASHSIZE
+
+

ev_staz watchers use a small hash table to distribute workload by +inotify watch id. The default size is 16 (or 1 with EV_MINIMAL), +usually more than enough. If you need to manage thousands of ev_stat +watchers you might want to increase this value (must be a power of +two).

EV_COMMON
@@ -2120,7 +2167,7 @@ documentation for ev_default_init.

Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)
Starting io/check/prepare/idle/signal/child watchers: O(1)
Stopping check/prepare/idle watchers: O(1)
-
Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % 16))
+
Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))
Finding the next timer per loop iteration: O(1)
Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)
Activating one watcher: O(1)