<meta name="description" content="Pod documentation for libev" />
<meta name="inputfile" content="<standard input>" />
<meta name="outputfile" content="<standard output>" />
- <meta name="created" content="Tue Nov 27 21:29:04 2007" />
+ <meta name="created" content="Wed Nov 28 12:27:27 2007" />
<meta name="generator" content="Pod::Xhtml 1.57" />
<link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head>
<body>
<code>ev_TYPE_set</code> is safe) and you must make sure the watcher is available to
libev (e.g. you cnanot <code>free ()</code> it).</p>
</dd>
- <dt>callback = ev_cb (ev_TYPE *watcher)</dt>
+ <dt>callback ev_cb (ev_TYPE *watcher)</dt>
<dd>
<p>Returns the callback currently set on the watcher.</p>
</dd>
}
</pre>
-<p>More interesting and less C-conformant ways of catsing your callback type
-have been omitted....</p>
+<p>More interesting and less C-conformant ways of casting your callback type
+instead have been omitted.</p>
+<p>Another common scenario is having some data structure with multiple
+watchers:</p>
+<pre> struct my_biggy
+ {
+ int some_data;
+ ev_timer t1;
+ ev_timer t2;
+ }
+</pre>
+<p>In this case getting the pointer to <code>my_biggy</code> is a bit more complicated,
+you need to use <code>offsetof</code>:</p>
+<pre> #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));
+ }
+
+
+</pre>
+
</div>
<h1 id="WATCHER_TYPES">WATCHER TYPES</h1>
<div id="WATCHER_TYPES_CONTENT">
otherwise always forced to be at least one) and all the other fields of
the stat buffer having unspecified contents.</p>
<p>Since there is no standard to do this, the portable implementation simply
-calls <code>stat (2)</code> regulalry on the path to see if it changed somehow. You
+calls <code>stat (2)</code> 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 <code>0</code> (highly recommended!) then a <i>suitable,
unspecified default</i> value will be used (which you can expect to be around
<p>This watcher type is not meant for massive numbers of stat watchers,
as even with OS-supported change notifications, this can be
resource-intensive.</p>
-<p>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.</p>
+<p>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 <code>ev_stat</code> 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.</p>
<dl>
<dt>ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)</dt>
<dt>ev_stat_set (ev_stat *, const char *path, ev_tstamp interval)</dt>
<dd>
<p>reserved for future expansion, works like the USE symbols above.</p>
</dd>
+ <dt>EV_USE_INOTIFY</dt>
+ <dd>
+ <p>If defined to be <code>1</code>, libev will compile in support for the Linux inotify
+interface to speed up <code>ev_stat</code> watchers. Its actual availability will
+be detected at runtime.</p>
+ </dd>
<dt>EV_H</dt>
<dd>
<p>The name of the <cite>ev.h</cite> header file used to include it. The default if
<p><code>ev_child</code> watchers use a small hash table to distribute workload by
pid. The default size is <code>16</code> (or <code>1</code> with <code>EV_MINIMAL</code>), usually more
than enough. If you need to manage thousands of children you might want to
-increase this value.</p>
+increase this value (<i>must</i> be a power of two).</p>
+ </dd>
+ <dt>EV_INOTIFY_HASHSIZE</dt>
+ <dd>
+ <p><code>ev_staz</code> watchers use a small hash table to distribute workload by
+inotify watch id. The default size is <code>16</code> (or <code>1</code> with <code>EV_MINIMAL</code>),
+usually more than enough. If you need to manage thousands of <code>ev_stat</code>
+watchers you might want to increase this value (<i>must</i> be a power of
+two).</p>
</dd>
<dt>EV_COMMON</dt>
<dd>
<dt>Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)</dt>
<dt>Starting io/check/prepare/idle/signal/child watchers: O(1)</dt>
<dt>Stopping check/prepare/idle watchers: O(1)</dt>
- <dt>Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % 16))</dt>
+ <dt>Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))</dt>
<dt>Finding the next timer per loop iteration: O(1)</dt>
<dt>Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)</dt>
<dt>Activating one watcher: O(1)</dt>