… | |
… | |
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="<standard input>" /> |
7 | <meta name="inputfile" content="<standard input>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
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 <ev.h> |
72 | #include <ev.h> |
|
|
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 ("stdin ready"); */ |
|
|
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 ("timeout"); */ |
|
|
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 (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ); |
|
|
101 | ev_io_start (loop, &stdin_watcher); |
|
|
102 | |
|
|
103 | /* simple non-repeating 5.5 second timeout */ |
|
|
104 | ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.); |
|
|
105 | ev_timer_start (loop, &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> |
… | |
… | |
179 | might be supported on the current system, you would need to look at |
219 | might be supported on the current system, you would need to look at |
180 | <code>ev_embeddable_backends () & ev_supported_backends ()</code>, likewise for |
220 | <code>ev_embeddable_backends () & ev_supported_backends ()</code>, likewise for |
181 | recommended ones.</p> |
221 | recommended 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 |
187 | realloc C function, the semantics are identical). It is used to allocate |
227 | identical to the realloc C function). It is used to allocate and free |
188 | and free memory (no surprises here). If it returns zero when memory |
228 | memory (no surprises here). If it returns zero when memory needs to be |
189 | needs to be allocated, the library might abort or take some potentially |
229 | allocated, the library might abort or take some potentially destructive |
190 | destructive action. The default is your system realloc function.</p> |
230 | action. 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, |
192 | free some memory if it cannot allocate memory, to use a special allocator, |
232 | free some memory if it cannot allocate memory, to use a special allocator, |
193 | or even to sleep a while and retry until some memory is available.</p> |
233 | or 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 |
195 | retries: better than mine).</p> |
235 | retries: 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 |
1998 | speed, define this symbol to <code>1</code>. Currently only used for gcc to override |
2038 | speed, define this symbol to <code>1</code>. Currently only used for gcc to override |
1999 | some inlining decisions, saves roughly 30% codesize of amd64.</p> |
2039 | some 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 |
|
|
2044 | pid. The default size is <code>16</code> (or <code>1</code> with <code>EV_MINIMAL</code>), usually more |
|
|
2045 | than enough. If you need to manage thousands of children you might want to |
|
|
2046 | increase 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 |
2004 | this macro to a something else you can include more and other types of |
2051 | this macro to a something else you can include more and other types of |
2005 | members. You have to define it each time you include one of the files, |
2052 | members. You have to define it each time you include one of the files, |