ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.html
(Generate patch)

Comparing libev/ev.html (file contents):
Revision 1.2 by root, Mon Nov 12 08:02:54 2007 UTC vs.
Revision 1.8 by root, Mon Nov 12 08:20:02 2007 UTC

4<head> 4<head>
5 <title>libev</title> 5 <title>libev</title>
6 <meta name="description" content="Pod documentation for libev" /> 6 <meta name="description" content="Pod documentation for libev" />
7 <meta name="inputfile" content="&lt;standard input&gt;" /> 7 <meta name="inputfile" content="&lt;standard input&gt;" />
8 <meta name="outputfile" content="&lt;standard output&gt;" /> 8 <meta name="outputfile" content="&lt;standard output&gt;" />
9 <meta name="created" content="Mon Nov 12 09:02:48 2007" /> 9 <meta name="created" content="Mon Nov 12 09:20:02 2007" />
10 <meta name="generator" content="Pod::Xhtml 1.57" /> 10 <meta name="generator" content="Pod::Xhtml 1.57" />
11<link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head> 11<link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head>
12<body> 12<body>
13<div class="pod"> 13<div class="pod">
14<!-- INDEX START --> 14<!-- INDEX START -->
26</ul> 26</ul>
27</li> 27</li>
28<li><a href="#WATCHER_TYPES">WATCHER TYPES</a> 28<li><a href="#WATCHER_TYPES">WATCHER TYPES</a>
29<ul><li><a href="#struct_ev_io_is_my_file_descriptor_r">struct ev_io - is my file descriptor readable or writable</a></li> 29<ul><li><a href="#struct_ev_io_is_my_file_descriptor_r">struct ev_io - is my file descriptor readable or writable</a></li>
30<li><a href="#struct_ev_timer_relative_and_optiona">struct ev_timer - relative and optionally recurring timeouts</a></li> 30<li><a href="#struct_ev_timer_relative_and_optiona">struct ev_timer - relative and optionally recurring timeouts</a></li>
31<li><a href="#ev_periodic">ev_periodic</a></li> 31<li><a href="#ev_periodic_to_cron_or_not_to_cron_i">ev_periodic - to cron or not to cron it</a></li>
32<li><a href="#ev_signal_signal_me_when_a_signal_ge">ev_signal - signal me when a signal gets signalled</a></li> 32<li><a href="#ev_signal_signal_me_when_a_signal_ge">ev_signal - signal me when a signal gets signalled</a></li>
33<li><a href="#ev_child_wait_for_pid_status_changes">ev_child - wait for pid status changes</a></li> 33<li><a href="#ev_child_wait_for_pid_status_changes">ev_child - wait for pid status changes</a></li>
34<li><a href="#ev_idle_when_you_ve_got_nothing_bett">ev_idle - when you've got nothing better to do</a></li> 34<li><a href="#ev_idle_when_you_ve_got_nothing_bett">ev_idle - when you've got nothing better to do</a></li>
35<li><a href="#prepare_and_check_your_hooks_into_th">prepare and check - your hooks into the event loop</a></li> 35<li><a href="#prepare_and_check_your_hooks_into_th">prepare and check - your hooks into the event loop</a></li>
36</ul> 36</ul>
55</div> 55</div>
56<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p> 56<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
57<div id="DESCRIPTION_CONTENT"> 57<div id="DESCRIPTION_CONTENT">
58<p>Libev is an event loop: you register interest in certain events (such as a 58<p>Libev is an event loop: you register interest in certain events (such as a
59file descriptor being readable or a timeout occuring), and it will manage 59file descriptor being readable or a timeout occuring), and it will manage
60these event sources and provide your program events.</p> 60these event sources and provide your program with events.</p>
61<p>To do this, it must take more or less complete control over your process 61<p>To do this, it must take more or less complete control over your process
62(or thread) by executing the <i>event loop</i> handler, and will then 62(or thread) by executing the <i>event loop</i> handler, and will then
63communicate events via a callback mechanism.</p> 63communicate events via a callback mechanism.</p>
64<p>You register interest in certain events by registering so-called <i>event 64<p>You register interest in certain events by registering so-called <i>event
65watchers</i>, which are relatively small C structures you initialise with the 65watchers</i>, which are relatively small C structures you initialise with the
71<div id="FEATURES_CONTENT"> 71<div id="FEATURES_CONTENT">
72<p>Libev supports select, poll, the linux-specific epoll and the bsd-specific 72<p>Libev supports select, poll, the linux-specific epoll and the bsd-specific
73kqueue mechanisms for file descriptor events, relative timers, absolute 73kqueue mechanisms for file descriptor events, relative timers, absolute
74timers with customised rescheduling, signal events, process status change 74timers with customised rescheduling, signal events, process status change
75events (related to SIGCHLD), and event watchers dealing with the event 75events (related to SIGCHLD), and event watchers dealing with the event
76loop mechanism itself (idle, prepare and check watchers).</p> 76loop mechanism itself (idle, prepare and check watchers). It also is quite
77fast (see this <a href="http://libev.schmorp.de/bench.html">benchmark</a> comparing
78it to libevent for example).</p>
77 79
78</div> 80</div>
79<h1 id="CONVENTIONS">CONVENTIONS</h1><p><a href="#TOP" class="toplink">Top</a></p> 81<h1 id="CONVENTIONS">CONVENTIONS</h1><p><a href="#TOP" class="toplink">Top</a></p>
80<div id="CONVENTIONS_CONTENT"> 82<div id="CONVENTIONS_CONTENT">
81<p>Libev is very configurable. In this manual the default configuration 83<p>Libev is very configurable. In this manual the default configuration
82will be described, which supports multiple event loops. For more info 84will be described, which supports multiple event loops. For more info
83about various configuraiton options please have a look at the file 85about various configuration options please have a look at the file
84<cite>README.embed</cite> in the libev distribution. If libev was configured without 86<cite>README.embed</cite> in the libev distribution. If libev was configured without
85support for multiple event loops, then all functions taking an initial 87support for multiple event loops, then all functions taking an initial
86argument of name <code>loop</code> (which is always of type <code>struct ev_loop *</code>) 88argument of name <code>loop</code> (which is always of type <code>struct ev_loop *</code>)
87will not have this argument.</p> 89will not have this argument.</p>
88 90
113not a problem.</p> 115not a problem.</p>
114 </dd> 116 </dd>
115 <dt>ev_set_allocator (void *(*cb)(void *ptr, long size))</dt> 117 <dt>ev_set_allocator (void *(*cb)(void *ptr, long size))</dt>
116 <dd> 118 <dd>
117 <p>Sets the allocation function to use (the prototype is similar to the 119 <p>Sets the allocation function to use (the prototype is similar to the
118realloc function). It is used to allocate and free memory (no surprises 120realloc C function, the semantics are identical). It is used to allocate
119here). If it returns zero when memory needs to be allocated, the library 121and free memory (no surprises here). If it returns zero when memory
120might abort or take some potentially destructive action. The default is 122needs to be allocated, the library might abort or take some potentially
121your system realloc function.</p> 123destructive action. The default is your system realloc function.</p>
122 <p>You could override this function in high-availability programs to, say, 124 <p>You could override this function in high-availability programs to, say,
123free some memory if it cannot allocate memory, to use a special allocator, 125free some memory if it cannot allocate memory, to use a special allocator,
124or even to sleep a while and retry until some memory is available.</p> 126or even to sleep a while and retry until some memory is available.</p>
125 </dd> 127 </dd>
126 <dt>ev_set_syserr_cb (void (*cb)(const char *msg));</dt> 128 <dt>ev_set_syserr_cb (void (*cb)(const char *msg));</dt>
127 <dd> 129 <dd>
128 <p>Set the callback function to call on a retryable syscall error (such 130 <p>Set the callback function to call on a retryable syscall error (such
129as failed select, poll, epoll_wait). The message is a printable string 131as failed select, poll, epoll_wait). The message is a printable string
130indicating the system call or subsystem causing the problem. If this 132indicating the system call or subsystem causing the problem. If this
131callback is set, then libev will expect it to remedy the sitution, no 133callback is set, then libev will expect it to remedy the sitution, no
132matter what, when it returns. That is, libev will geenrally retry the 134matter what, when it returns. That is, libev will generally retry the
133requested operation, or, if the condition doesn't go away, do bad stuff 135requested operation, or, if the condition doesn't go away, do bad stuff
134(such as abort).</p> 136(such as abort).</p>
135 </dd> 137 </dd>
136</dl> 138</dl>
137 139
141<p>An event loop is described by a <code>struct ev_loop *</code>. The library knows two 143<p>An event loop is described by a <code>struct ev_loop *</code>. The library knows two
142types of such loops, the <i>default</i> loop, which supports signals and child 144types of such loops, the <i>default</i> loop, which supports signals and child
143events, and dynamically created loops which do not.</p> 145events, and dynamically created loops which do not.</p>
144<p>If you use threads, a common model is to run the default event loop 146<p>If you use threads, a common model is to run the default event loop
145in your main thread (or in a separate thrad) and for each thread you 147in your main thread (or in a separate thrad) and for each thread you
146create, you also create another event loop. Libev itself does no lockign 148create, you also create another event loop. Libev itself does no locking
147whatsoever, so if you mix calls to different event loops, make sure you 149whatsoever, so if you mix calls to the same event loop in different
148lock (this is usually a bad idea, though, even if done right).</p> 150threads, make sure you lock (this is usually a bad idea, though, even if
151done correctly, because its hideous and inefficient).</p>
149<dl> 152<dl>
150 <dt>struct ev_loop *ev_default_loop (unsigned int flags)</dt> 153 <dt>struct ev_loop *ev_default_loop (unsigned int flags)</dt>
151 <dd> 154 <dd>
152 <p>This will initialise the default event loop if it hasn't been initialised 155 <p>This will initialise the default event loop if it hasn't been initialised
153yet and return it. If the default loop could not be initialised, returns 156yet and return it. If the default loop could not be initialised, returns
154false. If it already was initialised it simply returns it (and ignores the 157false. If it already was initialised it simply returns it (and ignores the
155flags).</p> 158flags).</p>
156 <p>If you don't know what event loop to use, use the one returned from this 159 <p>If you don't know what event loop to use, use the one returned from this
157function.</p> 160function.</p>
158 <p>The flags argument can be used to specify special behaviour or specific 161 <p>The flags argument can be used to specify special behaviour or specific
159backends to use, and is usually specified as 0 (or EVFLAG_AUTO)</p> 162backends to use, and is usually specified as 0 (or EVFLAG_AUTO).</p>
160 <p>It supports the following flags:</p> 163 <p>It supports the following flags:</p>
161 <p> 164 <p>
162 <dl> 165 <dl>
163 <dt>EVFLAG_AUTO</dt> 166 <dt>EVFLAG_AUTO</dt>
164 <dd> 167 <dd>
165 <p>The default flags value. Use this if you have no clue (its the right 168 <p>The default flags value. Use this if you have no clue (its the right
166thing, believe me).</p> 169thing, believe me).</p>
167 </dd> 170 </dd>
168 <dt>EVFLAG_NOENV</dt> 171 <dt>EVFLAG_NOENV</dt>
169 <dd> 172 <dd>
170 <p>If this flag bit is ored into the flag value then libev will <i>not</i> look 173 <p>If this flag bit is ored into the flag value (or the program runs setuid
171at the environment variable <code>LIBEV_FLAGS</code>. Otherwise (the default), this 174or setgid) then libev will <i>not</i> look at the environment variable
172environment variable will override the flags completely. This is useful 175<code>LIBEV_FLAGS</code>. Otherwise (the default), this environment variable will
176override the flags completely if it is found in the environment. This is
173to try out specific backends to tets their performance, or to work around 177useful to try out specific backends to test their performance, or to work
174bugs.</p> 178around bugs.</p>
175 </dd> 179 </dd>
176 <dt>EVMETHOD_SELECT portable select backend</dt> 180 <dt>EVMETHOD_SELECT portable select backend</dt>
177 <dt>EVMETHOD_POLL poll backend (everywhere except windows)</dt> 181 <dt>EVMETHOD_POLL poll backend (everywhere except windows)</dt>
178 <dt>EVMETHOD_EPOLL linux only</dt> 182 <dt>EVMETHOD_EPOLL linux only</dt>
179 <dt>EVMETHOD_KQUEUE some bsds only</dt> 183 <dt>EVMETHOD_KQUEUE some bsds only</dt>
316*)</code>), and you can stop watching for events at any time by calling the 320*)</code>), and you can stop watching for events at any time by calling the
317corresponding stop function (<code>ev_&lt;type&gt;_stop (loop, watcher *)</code>.</p> 321corresponding stop function (<code>ev_&lt;type&gt;_stop (loop, watcher *)</code>.</p>
318<p>As long as your watcher is active (has been started but not stopped) you 322<p>As long as your watcher is active (has been started but not stopped) you
319must not touch the values stored in it. Most specifically you must never 323must not touch the values stored in it. Most specifically you must never
320reinitialise it or call its set method.</p> 324reinitialise it or call its set method.</p>
321<p>You cna check wether an event is active by calling the <code>ev_is_active 325<p>You cna check whether an event is active by calling the <code>ev_is_active
322(watcher *)</code> macro. To see wether an event is outstanding (but the 326(watcher *)</code> macro. To see whether an event is outstanding (but the
323callback for it has not been called yet) you cna use the <code>ev_is_pending 327callback for it has not been called yet) you cna use the <code>ev_is_pending
324(watcher *)</code> macro.</p> 328(watcher *)</code> macro.</p>
325<p>Each and every callback receives the event loop pointer as first, the 329<p>Each and every callback receives the event loop pointer as first, the
326registered watcher structure as second, and a bitset of received events as 330registered watcher structure as second, and a bitset of received events as
327third argument.</p> 331third argument.</p>
422information given in the last section.</p> 426information given in the last section.</p>
423 427
424</div> 428</div>
425<h2 id="struct_ev_io_is_my_file_descriptor_r">struct ev_io - is my file descriptor readable or writable</h2> 429<h2 id="struct_ev_io_is_my_file_descriptor_r">struct ev_io - is my file descriptor readable or writable</h2>
426<div id="struct_ev_io_is_my_file_descriptor_r-2"> 430<div id="struct_ev_io_is_my_file_descriptor_r-2">
427<p>I/O watchers check wether a file descriptor is readable or writable 431<p>I/O watchers check whether a file descriptor is readable or writable
428in each iteration of the event loop (This behaviour is called 432in each iteration of the event loop (This behaviour is called
429level-triggering because you keep receiving events as long as the 433level-triggering because you keep receiving events as long as the
430condition persists. Remember you cna stop the watcher if you don't want to 434condition persists. Remember you cna stop the watcher if you don't want to
431act on the event and neither want to receive future events).</p> 435act on the event and neither want to receive future events).</p>
436<p>In general you can register as many read and/or write event watchers oer
437fd as you want (as long as you don't confuse yourself). Setting all file
438descriptors to non-blocking mode is also usually a good idea (but not
439required if you know what you are doing).</p>
440<p>You have to be careful with dup'ed file descriptors, though. Some backends
441(the linux epoll backend is a notable example) cannot handle dup'ed file
442descriptors correctly if you register interest in two or more fds pointing
443to the same file/socket etc. description.</p>
444<p>If you must do this, then force the use of a known-to-be-good backend
445(at the time of this writing, this includes only EVMETHOD_SELECT and
446EVMETHOD_POLL).</p>
432<dl> 447<dl>
433 <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt> 448 <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt>
434 <dt>ev_io_set (ev_io *, int fd, int events)</dt> 449 <dt>ev_io_set (ev_io *, int fd, int events)</dt>
435 <dd> 450 <dd>
436 <p>Configures an ev_io watcher. The fd is the file descriptor to rceeive 451 <p>Configures an ev_io watcher. The fd is the file descriptor to rceeive
480the timer, and again will automatically restart it if need be.</p> 495the timer, and again will automatically restart it if need be.</p>
481 </dd> 496 </dd>
482</dl> 497</dl>
483 498
484</div> 499</div>
485<h2 id="ev_periodic">ev_periodic</h2> 500<h2 id="ev_periodic_to_cron_or_not_to_cron_i">ev_periodic - to cron or not to cron it</h2>
486<div id="ev_periodic_CONTENT"> 501<div id="ev_periodic_to_cron_or_not_to_cron_i-2">
487<p>Periodic watchers are also timers of a kind, but they are very versatile 502<p>Periodic watchers are also timers of a kind, but they are very versatile
488(and unfortunately a bit complex).</p> 503(and unfortunately a bit complex).</p>
489<p>Unlike ev_timer's, they are not based on real time (or relative time) 504<p>Unlike ev_timer's, they are not based on real time (or relative time)
490but on wallclock time (absolute time). You can tell a periodic watcher 505but on wallclock time (absolute time). You can tell a periodic watcher
491to trigger &quot;at&quot; some specific point in time. For example, if you tell a 506to trigger &quot;at&quot; some specific point in time. For example, if you tell a

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines