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

Comparing libev/ev.html (file contents):
Revision 1.64 by root, Fri Dec 7 16:49:49 2007 UTC vs.
Revision 1.66 by root, Fri Dec 7 19:15:39 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="Fri Dec 7 17:49:47 2007" /> 9 <meta name="created" content="Fri Dec 7 20:07:44 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 -->
119</pre> 119</pre>
120 120
121</div> 121</div>
122<h1 id="DESCRIPTION">DESCRIPTION</h1> 122<h1 id="DESCRIPTION">DESCRIPTION</h1>
123<div id="DESCRIPTION_CONTENT"> 123<div id="DESCRIPTION_CONTENT">
124<p>The newest version of this document is also available as a html-formatted
125web page you might find easier to navigate when reading it for the first
126time: <a href="http://cvs.schmorp.de/libev/ev.html">http://cvs.schmorp.de/libev/ev.html</a>.</p>
124<p>Libev is an event loop: you register interest in certain events (such as a 127<p>Libev is an event loop: you register interest in certain events (such as a
125file descriptor being readable or a timeout occuring), and it will manage 128file descriptor being readable or a timeout occuring), and it will manage
126these event sources and provide your program with events.</p> 129these event sources and provide your program with events.</p>
127<p>To do this, it must take more or less complete control over your process 130<p>To do this, it must take more or less complete control over your process
128(or thread) by executing the <i>event loop</i> handler, and will then 131(or thread) by executing the <i>event loop</i> handler, and will then
917this situation even with a relatively standard program structure. Thus 920this situation even with a relatively standard program structure. Thus
918it is best to always use non-blocking I/O: An extra <code>read</code>(2) returning 921it is best to always use non-blocking I/O: An extra <code>read</code>(2) returning
919<code>EAGAIN</code> is far preferable to a program hanging until some data arrives.</p> 922<code>EAGAIN</code> is far preferable to a program hanging until some data arrives.</p>
920<p>If you cannot run the fd in non-blocking mode (for example you should not 923<p>If you cannot run the fd in non-blocking mode (for example you should not
921play around with an Xlib connection), then you have to seperately re-test 924play around with an Xlib connection), then you have to seperately re-test
922wether a file descriptor is really ready with a known-to-be good interface 925whether a file descriptor is really ready with a known-to-be good interface
923such as poll (fortunately in our Xlib example, Xlib already does this on 926such as poll (fortunately in our Xlib example, Xlib already does this on
924its own, so its quite safe to use).</p> 927its own, so its quite safe to use).</p>
925<dl> 928<dl>
926 <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt> 929 <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt>
927 <dt>ev_io_set (ev_io *, int fd, int events)</dt> 930 <dt>ev_io_set (ev_io *, int fd, int events)</dt>
1832 1835
1833</div> 1836</div>
1834<h1 id="MACRO_MAGIC">MACRO MAGIC</h1> 1837<h1 id="MACRO_MAGIC">MACRO MAGIC</h1>
1835<div id="MACRO_MAGIC_CONTENT"> 1838<div id="MACRO_MAGIC_CONTENT">
1836<p>Libev can be compiled with a variety of options, the most fundemantal is 1839<p>Libev can be compiled with a variety of options, the most fundemantal is
1837<code>EV_MULTIPLICITY</code>. This option determines wether (most) functions and 1840<code>EV_MULTIPLICITY</code>. This option determines whether (most) functions and
1838callbacks have an initial <code>struct ev_loop *</code> argument.</p> 1841callbacks have an initial <code>struct ev_loop *</code> argument.</p>
1839<p>To make it easier to write programs that cope with either variant, the 1842<p>To make it easier to write programs that cope with either variant, the
1840following macros are defined:</p> 1843following macros are defined:</p>
1841<dl> 1844<dl>
1842 <dt><code>EV_A</code>, <code>EV_A_</code></dt> 1845 <dt><code>EV_A</code>, <code>EV_A_</code></dt>
1872 <p>Similar to the other two macros, this gives you the value of the default 1875 <p>Similar to the other two macros, this gives you the value of the default
1873loop, if multiple loops are supported (&quot;ev loop default&quot;).</p> 1876loop, if multiple loops are supported (&quot;ev loop default&quot;).</p>
1874 </dd> 1877 </dd>
1875</dl> 1878</dl>
1876<p>Example: Declare and initialise a check watcher, utilising the above 1879<p>Example: Declare and initialise a check watcher, utilising the above
1877macros so it will work regardless of wether multiple loops are supported 1880macros so it will work regardless of whether multiple loops are supported
1878or not.</p> 1881or not.</p>
1879<pre> static void 1882<pre> static void
1880 check_cb (EV_P_ ev_timer *w, int revents) 1883 check_cb (EV_P_ ev_timer *w, int revents)
1881 { 1884 {
1882 ev_check_stop (EV_A_ w); 1885 ev_check_stop (EV_A_ w);
2109 <p>If undefined or defined to <code>1</code>, then all event-loop-specific functions 2112 <p>If undefined or defined to <code>1</code>, then all event-loop-specific functions
2110will have the <code>struct ev_loop *</code> as first argument, and you can create 2113will have the <code>struct ev_loop *</code> as first argument, and you can create
2111additional independent event loops. Otherwise there will be no support 2114additional independent event loops. Otherwise there will be no support
2112for multiple event loops and there is no first event loop pointer 2115for multiple event loops and there is no first event loop pointer
2113argument. Instead, all functions act on the single default loop.</p> 2116argument. Instead, all functions act on the single default loop.</p>
2117 </dd>
2118 <dt>EV_MINPRI</dt>
2119 <dt>EV_MAXPRI</dt>
2120 <dd>
2121 <p>The range of allowed priorities. <code>EV_MINPRI</code> must be smaller or equal to
2122<code>EV_MAXPRI</code>, but otherwise there are no non-obvious limitations. You can
2123provide for more priorities by overriding those symbols (usually defined
2124to be <code>-2</code> and <code>2</code>, respectively).</p>
2125 <p>When doing priority-based operations, libev usually has to linearly search
2126all the priorities, so having many of them (hundreds) uses a lot of space
2127and time, so using the defaults of five priorities (-2 .. +2) is usually
2128fine.</p>
2129 <p>If your embedding app does not need any priorities, defining these both to
2130<code>0</code> will save some memory and cpu.</p>
2114 </dd> 2131 </dd>
2115 <dt>EV_PERIODIC_ENABLE</dt> 2132 <dt>EV_PERIODIC_ENABLE</dt>
2116 <dd> 2133 <dd>
2117 <p>If undefined or defined to be <code>1</code>, then periodic timers are supported. If 2134 <p>If undefined or defined to be <code>1</code>, then periodic timers are supported. If
2118defined to be <code>0</code>, then they are not. Disabling them saves a few kB of 2135defined to be <code>0</code>, then they are not. Disabling them saves a few kB of
2225libev will be explained. For complexity discussions about backends see the 2242libev will be explained. For complexity discussions about backends see the
2226documentation for <code>ev_default_init</code>.</p> 2243documentation for <code>ev_default_init</code>.</p>
2227 <p> 2244 <p>
2228 <dl> 2245 <dl>
2229 <dt>Starting and stopping timer/periodic watchers: O(log skipped_other_timers)</dt> 2246 <dt>Starting and stopping timer/periodic watchers: O(log skipped_other_timers)</dt>
2247 <dd>
2248 <p>This means that, when you have a watcher that triggers in one hour and
2249there are 100 watchers that would trigger before that then inserting will
2250have to skip those 100 watchers.</p>
2251 </dd>
2230 <dt>Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)</dt> 2252 <dt>Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)</dt>
2253 <dd>
2254 <p>That means that for changing a timer costs less than removing/adding them
2255as only the relative motion in the event queue has to be paid for.</p>
2256 </dd>
2231 <dt>Starting io/check/prepare/idle/signal/child watchers: O(1)</dt> 2257 <dt>Starting io/check/prepare/idle/signal/child watchers: O(1)</dt>
2258 <dd>
2259 <p>These just add the watcher into an array or at the head of a list. If
2260the array needs to be extended libev needs to realloc and move the whole
2261array, but this happen asymptotically less and less with more watchers,
2262thus amortised O(1).</p>
2263 </dd>
2232 <dt>Stopping check/prepare/idle watchers: O(1)</dt> 2264 <dt>Stopping check/prepare/idle watchers: O(1)</dt>
2233 <dt>Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))</dt> 2265 <dt>Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))</dt>
2266 <dd>
2267 <p>These watchers are stored in lists then need to be walked to find the
2268correct watcher to remove. The lists are usually short (you don't usually
2269have many watchers waiting for the same fd or signal).</p>
2270 </dd>
2234 <dt>Finding the next timer per loop iteration: O(1)</dt> 2271 <dt>Finding the next timer per loop iteration: O(1)</dt>
2235 <dt>Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)</dt> 2272 <dt>Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)</dt>
2273 <dd>
2274 <p>A change means an I/O watcher gets started or stopped, which requires
2275libev to recalculate its status (and possibly tell the kernel).</p>
2276 </dd>
2236 <dt>Activating one watcher: O(1)</dt> 2277 <dt>Activating one watcher: O(1)</dt>
2278 <dt>Priority handling: O(number_of_priorities)</dt>
2279 <dd>
2280 <p>Priorities are implemented by allocating some space for each
2281priority. When doing priority-based operations, libev usually has to
2282linearly search all the priorities.</p>
2283 </dd>
2237 </dl> 2284 </dl>
2238 </p> 2285 </p>
2239 2286
2240 2287
2241 2288

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines