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

Comparing libev/ev.html (file contents):
Revision 1.50 by root, Tue Nov 27 10:59:11 2007 UTC vs.
Revision 1.53 by root, Tue Nov 27 20:15: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="Tue Nov 27 11:59:06 2007" /> 9 <meta name="created" content="Tue Nov 27 21:14:27 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 -->
66<p>libev - a high performance full-featured event loop written in C</p> 66<p>libev - a high performance full-featured event loop written in C</p>
67 67
68</div> 68</div>
69<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p> 69<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
70<div id="SYNOPSIS_CONTENT"> 70<div id="SYNOPSIS_CONTENT">
71<pre> /* this is the only header you need */
71<pre> #include &lt;ev.h&gt; 72 #include &lt;ev.h&gt;
73
74 /* what follows is a fully working example program */
75 ev_io stdin_watcher;
76 ev_timer timeout_watcher;
77
78 /* called when data readable on stdin */
79 static void
80 stdin_cb (EV_P_ struct ev_io *w, int revents)
81 {
82 /* puts (&quot;stdin ready&quot;); */
83 ev_io_stop (EV_A_ w); /* just a syntax example */
84 ev_unloop (EV_A_ EVUNLOOP_ALL); /* leave all loop calls */
85 }
86
87 static void
88 timeout_cb (EV_P_ struct ev_timer *w, int revents)
89 {
90 /* puts (&quot;timeout&quot;); */
91 ev_unloop (EV_A_ EVUNLOOP_ONE); /* leave one loop call */
92 }
93
94 int
95 main (void)
96 {
97 struct ev_loop *loop = ev_default_loop (0);
98
99 /* initialise an io watcher, then start it */
100 ev_io_init (&amp;stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
101 ev_io_start (loop, &amp;stdin_watcher);
102
103 /* simple non-repeating 5.5 second timeout */
104 ev_timer_init (&amp;timeout_watcher, timeout_cb, 5.5, 0.);
105 ev_timer_start (loop, &amp;timeout_watcher);
106
107 /* loop till timeout or data ready */
108 ev_loop (loop, 0);
109
110 return 0;
111 }
72 112
73</pre> 113</pre>
74 114
75</div> 115</div>
76<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p> 116<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
179might be supported on the current system, you would need to look at 219might be supported on the current system, you would need to look at
180<code>ev_embeddable_backends () &amp; ev_supported_backends ()</code>, likewise for 220<code>ev_embeddable_backends () &amp; ev_supported_backends ()</code>, likewise for
181recommended ones.</p> 221recommended ones.</p>
182 <p>See the description of <code>ev_embed</code> watchers for more info.</p> 222 <p>See the description of <code>ev_embed</code> watchers for more info.</p>
183 </dd> 223 </dd>
184 <dt>ev_set_allocator (void *(*cb)(void *ptr, long size))</dt> 224 <dt>ev_set_allocator (void *(*cb)(void *ptr, size_t size))</dt>
185 <dd> 225 <dd>
186 <p>Sets the allocation function to use (the prototype is similar to the 226 <p>Sets the allocation function to use (the prototype and semantics are
187realloc C function, the semantics are identical). It is used to allocate 227identical to the realloc C function). It is used to allocate and free
188and free memory (no surprises here). If it returns zero when memory 228memory (no surprises here). If it returns zero when memory needs to be
189needs to be allocated, the library might abort or take some potentially 229allocated, the library might abort or take some potentially destructive
190destructive action. The default is your system realloc function.</p> 230action. The default is your system realloc function.</p>
191 <p>You could override this function in high-availability programs to, say, 231 <p>You could override this function in high-availability programs to, say,
192free some memory if it cannot allocate memory, to use a special allocator, 232free some memory if it cannot allocate memory, to use a special allocator,
193or even to sleep a while and retry until some memory is available.</p> 233or even to sleep a while and retry until some memory is available.</p>
194 <p>Example: replace the libev allocator with one that waits a bit and then 234 <p>Example: replace the libev allocator with one that waits a bit and then
195retries: better than mine).</p> 235retries: better than mine).</p>
196<pre> static void * 236<pre> static void *
197 persistent_realloc (void *ptr, long size) 237 persistent_realloc (void *ptr, size_t size)
198 { 238 {
199 for (;;) 239 for (;;)
200 { 240 {
201 void *newptr = realloc (ptr, size); 241 void *newptr = realloc (ptr, size);
202 242
1996 <dd> 2036 <dd>
1997 <p>If you need to shave off some kilobytes of code at the expense of some 2037 <p>If you need to shave off some kilobytes of code at the expense of some
1998speed, define this symbol to <code>1</code>. Currently only used for gcc to override 2038speed, define this symbol to <code>1</code>. Currently only used for gcc to override
1999some inlining decisions, saves roughly 30% codesize of amd64.</p> 2039some inlining decisions, saves roughly 30% codesize of amd64.</p>
2000 </dd> 2040 </dd>
2041 <dt>EV_PID_HASHSIZE</dt>
2042 <dd>
2043 <p><code>ev_child</code> watchers use a small hash table to distribute workload by
2044pid. The default size is <code>16</code> (or <code>1</code> with <code>EV_MINIMAL</code>), usually more
2045than enough. If you need to manage thousands of children you might want to
2046increase this value.</p>
2047 </dd>
2001 <dt>EV_COMMON</dt> 2048 <dt>EV_COMMON</dt>
2002 <dd> 2049 <dd>
2003 <p>By default, all watchers have a <code>void *data</code> member. By redefining 2050 <p>By default, all watchers have a <code>void *data</code> member. By redefining
2004this macro to a something else you can include more and other types of 2051this macro to a something else you can include more and other types of
2005members. You have to define it each time you include one of the files, 2052members. You have to define it each time you include one of the files,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines