X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/924ae10c0376cdb4b581d30f7b8a258b6b9e4853..966d5d144261f49787f7f7bfe95ff35181cc9af5:/ev.3 diff --git a/ev.3 b/ev.3 index a2e0946..9aefdff 100644 --- a/ev.3 +++ b/ev.3 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title """ 1" -.TH "" 1 "2007-11-27" "perl v5.8.8" "User Contributed Perl Documentation" +.TH "" 1 "2007-11-28" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" libev \- a high performance full\-featured event loop written in C .SH "SYNOPSIS" @@ -212,12 +212,13 @@ details of the event, and then hand it over to libev by \fIstarting\fR the watcher. .SH "FEATURES" .IX Header "FEATURES" -Libev supports \f(CW\*(C`select\*(C'\fR, \f(CW\*(C`poll\*(C'\fR, the linux-specific \f(CW\*(C`epoll\*(C'\fR, the -bsd-specific \f(CW\*(C`kqueue\*(C'\fR and the solaris-specific event port mechanisms -for file descriptor events (\f(CW\*(C`ev_io\*(C'\fR), relative timers (\f(CW\*(C`ev_timer\*(C'\fR), -absolute timers with customised rescheduling (\f(CW\*(C`ev_periodic\*(C'\fR), synchronous -signals (\f(CW\*(C`ev_signal\*(C'\fR), process status change events (\f(CW\*(C`ev_child\*(C'\fR), and -event watchers dealing with the event loop mechanism itself (\f(CW\*(C`ev_idle\*(C'\fR, +Libev supports \f(CW\*(C`select\*(C'\fR, \f(CW\*(C`poll\*(C'\fR, the Linux-specific \f(CW\*(C`epoll\*(C'\fR, the +BSD-specific \f(CW\*(C`kqueue\*(C'\fR and the Solaris-specific event port mechanisms +for file descriptor events (\f(CW\*(C`ev_io\*(C'\fR), the Linux \f(CW\*(C`inotify\*(C'\fR interface +(for \f(CW\*(C`ev_stat\*(C'\fR), relative timers (\f(CW\*(C`ev_timer\*(C'\fR), absolute timers +with customised rescheduling (\f(CW\*(C`ev_periodic\*(C'\fR), synchronous signals +(\f(CW\*(C`ev_signal\*(C'\fR), process status change events (\f(CW\*(C`ev_child\*(C'\fR), and event +watchers dealing with the event loop mechanism itself (\f(CW\*(C`ev_idle\*(C'\fR, \&\f(CW\*(C`ev_embed\*(C'\fR, \f(CW\*(C`ev_prepare\*(C'\fR and \f(CW\*(C`ev_check\*(C'\fR watchers) as well as file watchers (\f(CW\*(C`ev_stat\*(C'\fR) and even limited support for fork events (\f(CW\*(C`ev_fork\*(C'\fR). @@ -858,8 +859,8 @@ events but its callback has not yet been invoked). As long as a watcher is pending (but not active) you must not call an init function on it (but \&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe) and you must make sure the watcher is available to libev (e.g. you cnanot \f(CW\*(C`free ()\*(C'\fR it). -.IP "callback = ev_cb (ev_TYPE *watcher)" 4 -.IX Item "callback = ev_cb (ev_TYPE *watcher)" +.IP "callback ev_cb (ev_TYPE *watcher)" 4 +.IX Item "callback ev_cb (ev_TYPE *watcher)" Returns the callback currently set on the watcher. .IP "ev_cb_set (ev_TYPE *watcher, callback)" 4 .IX Item "ev_cb_set (ev_TYPE *watcher, callback)" @@ -895,8 +896,45 @@ can cast it back to your own type: \& } .Ve .PP -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. +.PP +Another common scenario is having some data structure with multiple +watchers: +.PP +.Vb 6 +\& struct my_biggy +\& { +\& int some_data; +\& ev_timer t1; +\& ev_timer t2; +\& } +.Ve +.PP +In this case getting the pointer to \f(CW\*(C`my_biggy\*(C'\fR is a bit more complicated, +you need to use \f(CW\*(C`offsetof\*(C'\fR: +.PP +.Vb 1 +\& #include +.Ve +.PP +.Vb 6 +\& 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)); +\& } +.Ve +.PP +.Vb 6 +\& 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)); +\& } +.Ve .SH "WATCHER TYPES" .IX Header "WATCHER TYPES" This section describes each watcher in detail, but will not repeat @@ -1348,7 +1386,7 @@ otherwise always forced to be at least one) and all the other fields of the stat buffer having unspecified contents. .PP Since there is no standard to do this, the portable implementation simply -calls \f(CW\*(C`stat (2)\*(C'\fR regulalry on the path to see if it changed somehow. You +calls \f(CW\*(C`stat (2)\*(C'\fR 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 \f(CW0\fR (highly recommended!) then a \fIsuitable, unspecified default\fR value will be used (which you can expect to be around @@ -1360,8 +1398,13 @@ This watcher type is not meant for massive numbers of stat watchers, as even with OS-supported change notifications, this can be resource\-intensive. .PP -At the time of this writing, no specific \s-1OS\s0 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 \f(CW\*(C`ev_stat\*(C'\fR 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. .IP "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" 4 .IX Item "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" .PD 0 @@ -2135,6 +2178,11 @@ backend for Solaris 10 systems. .IP "\s-1EV_USE_DEVPOLL\s0" 4 .IX Item "EV_USE_DEVPOLL" reserved for future expansion, works like the \s-1USE\s0 symbols above. +.IP "\s-1EV_USE_INOTIFY\s0" 4 +.IX Item "EV_USE_INOTIFY" +If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify +interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will +be detected at runtime. .IP "\s-1EV_H\s0" 4 .IX Item "EV_H" The name of the \fIev.h\fR header file used to include it. The default if @@ -2189,7 +2237,14 @@ some inlining decisions, saves roughly 30% codesize of amd64. \&\f(CW\*(C`ev_child\*(C'\fR watchers use a small hash table to distribute workload by pid. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), usually more than enough. If you need to manage thousands of children you might want to -increase this value. +increase this value (\fImust\fR be a power of two). +.IP "\s-1EV_INOTIFY_HASHSIZE\s0" 4 +.IX Item "EV_INOTIFY_HASHSIZE" +\&\f(CW\*(C`ev_staz\*(C'\fR watchers use a small hash table to distribute workload by +inotify watch id. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), +usually more than enough. If you need to manage thousands of \f(CW\*(C`ev_stat\*(C'\fR +watchers you might want to increase this value (\fImust\fR be a power of +two). .IP "\s-1EV_COMMON\s0" 4 .IX Item "EV_COMMON" By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining @@ -2263,8 +2318,8 @@ documentation for \f(CW\*(C`ev_default_init\*(C'\fR. .IX Item "Starting io/check/prepare/idle/signal/child watchers: O(1)" .IP "Stopping check/prepare/idle watchers: O(1)" 4 .IX Item "Stopping check/prepare/idle watchers: O(1)" -.IP "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % 16))" 4 -.IX Item "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % 16))" +.IP "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % \s-1EV_PID_HASHSIZE\s0))" 4 +.IX Item "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))" .IP "Finding the next timer per loop iteration: O(1)" 4 .IX Item "Finding the next timer per loop iteration: O(1)" .IP "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 4