<meta name="description" content="Pod documentation for libev" />
<meta name="inputfile" content="<standard input>" />
<meta name="outputfile" content="<standard output>" />
- <meta name="created" content="Mon Nov 12 09:02:48 2007" />
+ <meta name="created" content="Mon Nov 12 09:20:02 2007" />
<meta name="generator" content="Pod::Xhtml 1.57" />
<link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head>
<body>
<li><a href="#WATCHER_TYPES">WATCHER TYPES</a>
<ul><li><a href="#struct_ev_io_is_my_file_descriptor_r">struct ev_io - is my file descriptor readable or writable</a></li>
<li><a href="#struct_ev_timer_relative_and_optiona">struct ev_timer - relative and optionally recurring timeouts</a></li>
-<li><a href="#ev_periodic">ev_periodic</a></li>
+<li><a href="#ev_periodic_to_cron_or_not_to_cron_i">ev_periodic - to cron or not to cron it</a></li>
<li><a href="#ev_signal_signal_me_when_a_signal_ge">ev_signal - signal me when a signal gets signalled</a></li>
<li><a href="#ev_child_wait_for_pid_status_changes">ev_child - wait for pid status changes</a></li>
<li><a href="#ev_idle_when_you_ve_got_nothing_bett">ev_idle - when you've got nothing better to do</a></li>
<div id="DESCRIPTION_CONTENT">
<p>Libev is an event loop: you register interest in certain events (such as a
file descriptor being readable or a timeout occuring), and it will manage
-these event sources and provide your program events.</p>
+these event sources and provide your program with events.</p>
<p>To do this, it must take more or less complete control over your process
(or thread) by executing the <i>event loop</i> handler, and will then
communicate events via a callback mechanism.</p>
kqueue mechanisms for file descriptor events, relative timers, absolute
timers with customised rescheduling, signal events, process status change
events (related to SIGCHLD), and event watchers dealing with the event
-loop mechanism itself (idle, prepare and check watchers).</p>
+loop mechanism itself (idle, prepare and check watchers). It also is quite
+fast (see this <a href="http://libev.schmorp.de/bench.html">benchmark</a> comparing
+it to libevent for example).</p>
</div>
<h1 id="CONVENTIONS">CONVENTIONS</h1><p><a href="#TOP" class="toplink">Top</a></p>
<div id="CONVENTIONS_CONTENT">
<p>Libev is very configurable. In this manual the default configuration
will be described, which supports multiple event loops. For more info
-about various configuraiton options please have a look at the file
+about various configuration options please have a look at the file
<cite>README.embed</cite> in the libev distribution. If libev was configured without
support for multiple event loops, then all functions taking an initial
argument of name <code>loop</code> (which is always of type <code>struct ev_loop *</code>)
<dt>ev_set_allocator (void *(*cb)(void *ptr, long size))</dt>
<dd>
<p>Sets the allocation function to use (the prototype is similar to the
-realloc function). It is used to allocate and free memory (no surprises
-here). If it returns zero when memory needs to be allocated, the library
-might abort or take some potentially destructive action. The default is
-your system realloc function.</p>
+realloc C function, the semantics are identical). It is used to allocate
+and free memory (no surprises here). If it returns zero when memory
+needs to be allocated, the library might abort or take some potentially
+destructive action. The default is your system realloc function.</p>
<p>You could override this function in high-availability programs to, say,
free some memory if it cannot allocate memory, to use a special allocator,
or even to sleep a while and retry until some memory is available.</p>
as failed select, poll, epoll_wait). The message is a printable string
indicating the system call or subsystem causing the problem. If this
callback is set, then libev will expect it to remedy the sitution, no
-matter what, when it returns. That is, libev will geenrally retry the
+matter what, when it returns. That is, libev will generally retry the
requested operation, or, if the condition doesn't go away, do bad stuff
(such as abort).</p>
</dd>
events, and dynamically created loops which do not.</p>
<p>If you use threads, a common model is to run the default event loop
in your main thread (or in a separate thrad) and for each thread you
-create, you also create another event loop. Libev itself does no lockign
-whatsoever, so if you mix calls to different event loops, make sure you
-lock (this is usually a bad idea, though, even if done right).</p>
+create, you also create another event loop. Libev itself does no locking
+whatsoever, so if you mix calls to the same event loop in different
+threads, make sure you lock (this is usually a bad idea, though, even if
+done correctly, because its hideous and inefficient).</p>
<dl>
<dt>struct ev_loop *ev_default_loop (unsigned int flags)</dt>
<dd>
<p>If you don't know what event loop to use, use the one returned from this
function.</p>
<p>The flags argument can be used to specify special behaviour or specific
-backends to use, and is usually specified as 0 (or EVFLAG_AUTO)</p>
+backends to use, and is usually specified as 0 (or EVFLAG_AUTO).</p>
<p>It supports the following flags:</p>
<p>
<dl>
</dd>
<dt>EVFLAG_NOENV</dt>
<dd>
- <p>If this flag bit is ored into the flag value then libev will <i>not</i> look
-at the environment variable <code>LIBEV_FLAGS</code>. Otherwise (the default), this
-environment variable will override the flags completely. This is useful
-to try out specific backends to tets their performance, or to work around
-bugs.</p>
+ <p>If this flag bit is ored into the flag value (or the program runs setuid
+or setgid) then libev will <i>not</i> look at the environment variable
+<code>LIBEV_FLAGS</code>. Otherwise (the default), this environment variable will
+override the flags completely if it is found in the environment. This is
+useful to try out specific backends to test their performance, or to work
+around bugs.</p>
</dd>
<dt>EVMETHOD_SELECT portable select backend</dt>
<dt>EVMETHOD_POLL poll backend (everywhere except windows)</dt>
<p>As long as your watcher is active (has been started but not stopped) you
must not touch the values stored in it. Most specifically you must never
reinitialise it or call its set method.</p>
-<p>You cna check wether an event is active by calling the <code>ev_is_active
-(watcher *)</code> macro. To see wether an event is outstanding (but the
+<p>You cna check whether an event is active by calling the <code>ev_is_active
+(watcher *)</code> macro. To see whether an event is outstanding (but the
callback for it has not been called yet) you cna use the <code>ev_is_pending
(watcher *)</code> macro.</p>
<p>Each and every callback receives the event loop pointer as first, the
</div>
<h2 id="struct_ev_io_is_my_file_descriptor_r">struct ev_io - is my file descriptor readable or writable</h2>
<div id="struct_ev_io_is_my_file_descriptor_r-2">
-<p>I/O watchers check wether a file descriptor is readable or writable
+<p>I/O watchers check whether a file descriptor is readable or writable
in each iteration of the event loop (This behaviour is called
level-triggering because you keep receiving events as long as the
condition persists. Remember you cna stop the watcher if you don't want to
act on the event and neither want to receive future events).</p>
+<p>In general you can register as many read and/or write event watchers oer
+fd as you want (as long as you don't confuse yourself). Setting all file
+descriptors to non-blocking mode is also usually a good idea (but not
+required if you know what you are doing).</p>
+<p>You have to be careful with dup'ed file descriptors, though. Some backends
+(the linux epoll backend is a notable example) cannot handle dup'ed file
+descriptors correctly if you register interest in two or more fds pointing
+to the same file/socket etc. description.</p>
+<p>If you must do this, then force the use of a known-to-be-good backend
+(at the time of this writing, this includes only EVMETHOD_SELECT and
+EVMETHOD_POLL).</p>
<dl>
<dt>ev_io_init (ev_io *, callback, int fd, int events)</dt>
<dt>ev_io_set (ev_io *, int fd, int events)</dt>
</dl>
</div>
-<h2 id="ev_periodic">ev_periodic</h2>
-<div id="ev_periodic_CONTENT">
+<h2 id="ev_periodic_to_cron_or_not_to_cron_i">ev_periodic - to cron or not to cron it</h2>
+<div id="ev_periodic_to_cron_or_not_to_cron_i-2">
<p>Periodic watchers are also timers of a kind, but they are very versatile
(and unfortunately a bit complex).</p>
<p>Unlike ev_timer's, they are not based on real time (or relative time)