summaryrefslogtreecommitdiff
path: root/ev.html
diff options
context:
space:
mode:
Diffstat (limited to 'ev.html')
-rw-r--r--ev.html210
1 files changed, 198 insertions, 12 deletions
diff --git a/ev.html b/ev.html
index b13b6ae..f24dedd 100644
--- a/ev.html
+++ b/ev.html
@@ -6,7 +6,7 @@
<meta name="description" content="Pod documentation for libev" />
<meta name="inputfile" content="&lt;standard input&gt;" />
<meta name="outputfile" content="&lt;standard output&gt;" />
- <meta name="created" content="Mon Nov 26 11:20:35 2007" />
+ <meta name="created" content="Tue Nov 27 09:11:42 2007" />
<meta name="generator" content="Pod::Xhtml 1.57" />
<link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head>
<body>
@@ -33,6 +33,7 @@
<li><a href="#code_ev_periodic_code_to_cron_or_not"><code>ev_periodic</code> - to cron or not to cron?</a></li>
<li><a href="#code_ev_signal_code_signal_me_when_a"><code>ev_signal</code> - signal me when a signal gets signalled!</a></li>
<li><a href="#code_ev_child_code_watch_out_for_pro"><code>ev_child</code> - watch out for process status changes</a></li>
+<li><a href="#code_ev_stat_code_did_the_file_attri"><code>ev_stat</code> - did the file attributes just change?</a></li>
<li><a href="#code_ev_idle_code_when_you_ve_got_no"><code>ev_idle</code> - when you've got nothing better to do...</a></li>
<li><a href="#code_ev_prepare_code_and_code_ev_che"><code>ev_prepare</code> and <code>ev_check</code> - customise your event loop!</a></li>
<li><a href="#code_ev_embed_code_when_one_backend_"><code>ev_embed</code> - when one backend isn't enough...</a></li>
@@ -588,6 +589,10 @@ writable.</p>
<dd>
<p>The pid specified in the <code>ev_child</code> watcher has received a status change.</p>
</dd>
+ <dt><code>EV_STAT</code></dt>
+ <dd>
+ <p>The path specified in the <code>ev_stat</code> watcher changed its attributes somehow.</p>
+ </dd>
<dt><code>EV_IDLE</code></dt>
<dd>
<p>The <code>ev_idle</code> watcher has determined that you have nothing better to do.</p>
@@ -734,7 +739,16 @@ have been omitted....</p>
<h1 id="WATCHER_TYPES">WATCHER TYPES</h1><p><a href="#TOP" class="toplink">Top</a></p>
<div id="WATCHER_TYPES_CONTENT">
<p>This section describes each watcher in detail, but will not repeat
-information given in the last section.</p>
+information given in the last section. Any initialisation/set macros,
+functions and members specific to the watcher type are explained.</p>
+<p>Members are additionally marked with either <i>[read-only]</i>, meaning that,
+while the watcher is active, you can look at the member and expect some
+sensible content, but you must not modify it (you can modify it while the
+watcher is stopped to your hearts content), or <i>[read-write]</i>, which
+means you can expect it to have some sensible content while the watcher
+is active, but you can also modify it. Modifying it may not do something
+sensible or take immediate effect (or do anything at all), but libev will
+not crash or malfunction in any way.</p>
@@ -783,6 +797,14 @@ its own, so its quite safe to use).</p>
rceeive events for and events is either <code>EV_READ</code>, <code>EV_WRITE</code> or
<code>EV_READ | EV_WRITE</code> to receive the given events.</p>
</dd>
+ <dt>int fd [read-only]</dt>
+ <dd>
+ <p>The file descriptor being watched.</p>
+ </dd>
+ <dt>int events [read-only]</dt>
+ <dd>
+ <p>The events being watched.</p>
+ </dd>
</dl>
<p>Example: call <code>stdin_readable_cb</code> when STDIN_FILENO has become, well
readable, but only once. Since it is likely line-buffered, you could
@@ -849,13 +871,34 @@ repeating. The exact semantics are:</p>
<p>If the timer is repeating, either start it if necessary (with the repeat
value), or reset the running timer to the repeat value.</p>
<p>This sounds a bit complicated, but here is a useful and typical
-example: Imagine you have a tcp connection and you want a so-called idle
-timeout, that is, you want to be called when there have been, say, 60
-seconds of inactivity on the socket. The easiest way to do this is to
-configure an <code>ev_timer</code> with after=repeat=60 and calling ev_timer_again each
-time you successfully read or write some data. If you go into an idle
-state where you do not expect data to travel on the socket, you can stop
-the timer, and again will automatically restart it if need be.</p>
+example: Imagine you have a tcp connection and you want a so-called
+idle timeout, that is, you want to be called when there have been,
+say, 60 seconds of inactivity on the socket. The easiest way to do
+this is to configure an <code>ev_timer</code> with <code>after</code>=<code>repeat</code>=<code>60</code> and calling
+<code>ev_timer_again</code> each time you successfully read or write some data. If
+you go into an idle state where you do not expect data to travel on the
+socket, you can stop the timer, and again will automatically restart it if
+need be.</p>
+ <p>You can also ignore the <code>after</code> value and <code>ev_timer_start</code> altogether
+and only ever use the <code>repeat</code> value:</p>
+<pre> ev_timer_init (timer, callback, 0., 5.);
+ ev_timer_again (loop, timer);
+ ...
+ timer-&gt;again = 17.;
+ ev_timer_again (loop, timer);
+ ...
+ timer-&gt;again = 10.;
+ ev_timer_again (loop, timer);
+
+</pre>
+ <p>This is more efficient then stopping/starting the timer eahc time you want
+to modify its timeout value.</p>
+ </dd>
+ <dt>ev_tstamp repeat [read-write]</dt>
+ <dd>
+ <p>The current <code>repeat</code> value. Will be used each time the watcher times out
+or <code>ev_timer_again</code> is called and determines the next timeout (if any),
+which is also when any modifications are taken into account.</p>
</dd>
</dl>
<p>Example: create a timer that fires after 60 seconds.</p>
@@ -983,6 +1026,18 @@ 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).</p>
</dd>
+ <dt>ev_tstamp interval [read-write]</dt>
+ <dd>
+ <p>The current interval value. Can be modified any time, but changes only
+take effect when the periodic timer fires or <code>ev_periodic_again</code> is being
+called.</p>
+ </dd>
+ <dt>ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) [read-write]</dt>
+ <dd>
+ <p>The current reschedule callback, or <code>0</code>, if this functionality is
+switched off. Can be changed any time, but changes only take effect when
+the periodic timer fires or <code>ev_periodic_again</code> is being called.</p>
+ </dd>
</dl>
<p>Example: call a callback every hour, or, more precisely, whenever the
system clock is divisible by 3600. The callback invocation times have
@@ -1041,6 +1096,10 @@ SIG_DFL (regardless of what it was set to before).</p>
<p>Configures the watcher to trigger on the given signal number (usually one
of the <code>SIGxxx</code> constants).</p>
</dd>
+ <dt>int signum [read-only]</dt>
+ <dd>
+ <p>The signal the watcher watches out for.</p>
+ </dd>
</dl>
@@ -1063,6 +1122,19 @@ the status word (use the macros from <code>sys/wait.h</code> and see your system
<code>waitpid</code> documentation). The <code>rpid</code> member contains the pid of the
process causing the status change.</p>
</dd>
+ <dt>int pid [read-only]</dt>
+ <dd>
+ <p>The process id this watcher watches out for, or <code>0</code>, meaning any process id.</p>
+ </dd>
+ <dt>int rpid [read-write]</dt>
+ <dd>
+ <p>The process id that detected a status change.</p>
+ </dd>
+ <dt>int rstatus [read-write]</dt>
+ <dd>
+ <p>The process exit/trace status caused by <code>rpid</code> (see your systems
+<code>waitpid</code> and <code>sys/wait.h</code> documentation for details).</p>
+ </dd>
</dl>
<p>Example: try to exit cleanly on SIGINT and SIGTERM.</p>
<pre> static void
@@ -1081,6 +1153,99 @@ process causing the status change.</p>
</pre>
</div>
+<h2 id="code_ev_stat_code_did_the_file_attri"><code>ev_stat</code> - did the file attributes just change?</h2>
+<div id="code_ev_stat_code_did_the_file_attri-2">
+<p>This watches a filesystem path for attribute changes. That is, it calls
+<code>stat</code> regularly (or when the OS says it changed) and sees if it changed
+compared to the last time, invoking the callback if it did.</p>
+<p>The path does not need to exist: changing from &quot;path exists&quot; to &quot;path does
+not exist&quot; is a status change like any other. The condition &quot;path does
+not exist&quot; is signified by the <code>st_nlink</code> field being zero (which is
+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
+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
+five seconds, although this might change dynamically). Libev will also
+impose a minimum interval which is currently around <code>0.1</code>, but thats
+usually overkill.</p>
+<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>
+<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>Configures the watcher to wait for status changes of the given
+<code>path</code>. The <code>interval</code> is a hint on how quickly a change is expected to
+be detected and should normally be specified as <code>0</code> to let libev choose
+a suitable value. The memory pointed to by <code>path</code> must point to the same
+path for as long as the watcher is active.</p>
+ <p>The callback will be receive <code>EV_STAT</code> when a change was detected,
+relative to the attributes at the time the watcher was started (or the
+last change was detected).</p>
+ </dd>
+ <dt>ev_stat_stat (ev_stat *)</dt>
+ <dd>
+ <p>Updates the stat buffer immediately with new values. If you change the
+watched path in your callback, you could call this fucntion to avoid
+detecting this change (while introducing a race condition). Can also be
+useful simply to find out the new values.</p>
+ </dd>
+ <dt>ev_statdata attr [read-only]</dt>
+ <dd>
+ <p>The most-recently detected attributes of the file. Although the type is of
+<code>ev_statdata</code>, this is usually the (or one of the) <code>struct stat</code> types
+suitable for your system. If the <code>st_nlink</code> member is <code>0</code>, then there
+was some error while <code>stat</code>ing the file.</p>
+ </dd>
+ <dt>ev_statdata prev [read-only]</dt>
+ <dd>
+ <p>The previous attributes of the file. The callback gets invoked whenever
+<code>prev</code> != <code>attr</code>.</p>
+ </dd>
+ <dt>ev_tstamp interval [read-only]</dt>
+ <dd>
+ <p>The specified interval.</p>
+ </dd>
+ <dt>const char *path [read-only]</dt>
+ <dd>
+ <p>The filesystem path that is being watched.</p>
+ </dd>
+</dl>
+<p>Example: Watch <code>/etc/passwd</code> for attribute changes.</p>
+<pre> static void
+ passwd_cb (struct ev_loop *loop, ev_stat *w, int revents)
+ {
+ /* /etc/passwd changed in some way */
+ if (w-&gt;attr.st_nlink)
+ {
+ printf (&quot;passwd current size %ld\n&quot;, (long)w-&gt;attr.st_size);
+ printf (&quot;passwd current atime %ld\n&quot;, (long)w-&gt;attr.st_mtime);
+ printf (&quot;passwd current mtime %ld\n&quot;, (long)w-&gt;attr.st_mtime);
+ }
+ else
+ /* you shalt not abuse printf for puts */
+ puts (&quot;wow, /etc/passwd is not there, expect problems. &quot;
+ &quot;if this is windows, they already arrived\n&quot;);
+ }
+
+ ...
+ ev_stat passwd;
+
+ ev_stat_init (&amp;passwd, passwd_cb, &quot;/etc/passwd&quot;);
+ ev_stat_start (loop, &amp;passwd);
+
+
+
+
+</pre>
+
+</div>
<h2 id="code_ev_idle_code_when_you_ve_got_no"><code>ev_idle</code> - when you've got nothing better to do...</h2>
<div id="code_ev_idle_code_when_you_ve_got_no-2">
<p>Idle watchers trigger events when there are no other events are pending
@@ -1306,6 +1471,10 @@ if you do not want thta, you need to temporarily stop the embed watcher).</p>
similarly to <code>ev_loop (embedded_loop, EVLOOP_NONBLOCK)</code>, but in the most
apropriate way for embedded loops.</p>
</dd>
+ <dt>struct ev_loop *loop [read-only]</dt>
+ <dd>
+ <p>The embedded event loop.</p>
+ </dd>
</dl>
@@ -1704,10 +1873,27 @@ additional independent event loops. Otherwise there will be no support
for multiple event loops and there is no first event loop pointer
argument. Instead, all functions act on the single default loop.</p>
</dd>
- <dt>EV_PERIODICS</dt>
+ <dt>EV_PERIODIC_ENABLE</dt>
+ <dd>
+ <p>If undefined or defined to be <code>1</code>, then periodic timers are supported. If
+defined to be <code>0</code>, then they are not. Disabling them saves a few kB of
+code.</p>
+ </dd>
+ <dt>EV_EMBED_ENABLE</dt>
+ <dd>
+ <p>If undefined or defined to be <code>1</code>, then embed watchers are supported. If
+defined to be <code>0</code>, then they are not.</p>
+ </dd>
+ <dt>EV_STAT_ENABLE</dt>
+ <dd>
+ <p>If undefined or defined to be <code>1</code>, then stat watchers are supported. If
+defined to be <code>0</code>, then they are not.</p>
+ </dd>
+ <dt>EV_MINIMAL</dt>
<dd>
- <p>If undefined or defined to be <code>1</code>, then periodic timers are supported,
-otherwise not. This saves a few kb of code.</p>
+ <p>If you need to shave off some kilobytes of code at the expense of some
+speed, define this symbol to <code>1</code>. Currently only used for gcc to override
+some inlining decisions, saves roughly 30% codesize of amd64.</p>
</dd>
<dt>EV_COMMON</dt>
<dd>