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

Comparing libev/ev.3 (file contents):
Revision 1.24 by root, Tue Nov 27 10:59:10 2007 UTC vs.
Revision 1.27 by root, Tue Nov 27 20:15:01 2007 UTC

132.TH "<STANDARD INPUT>" 1 "2007-11-27" "perl v5.8.8" "User Contributed Perl Documentation" 132.TH "<STANDARD INPUT>" 1 "2007-11-27" "perl v5.8.8" "User Contributed Perl Documentation"
133.SH "NAME" 133.SH "NAME"
134libev \- a high performance full\-featured event loop written in C 134libev \- a high performance full\-featured event loop written in C
135.SH "SYNOPSIS" 135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS" 136.IX Header "SYNOPSIS"
137.Vb 1 137.Vb 2
138\& /* this is the only header you need */
138\& #include <ev.h> 139\& #include <ev.h>
140.Ve
141.PP
142.Vb 3
143\& /* what follows is a fully working example program */
144\& ev_io stdin_watcher;
145\& ev_timer timeout_watcher;
146.Ve
147.PP
148.Vb 8
149\& /* called when data readable on stdin */
150\& static void
151\& stdin_cb (EV_P_ struct ev_io *w, int revents)
152\& {
153\& /* puts ("stdin ready"); */
154\& ev_io_stop (EV_A_ w); /* just a syntax example */
155\& ev_unloop (EV_A_ EVUNLOOP_ALL); /* leave all loop calls */
156\& }
157.Ve
158.PP
159.Vb 6
160\& static void
161\& timeout_cb (EV_P_ struct ev_timer *w, int revents)
162\& {
163\& /* puts ("timeout"); */
164\& ev_unloop (EV_A_ EVUNLOOP_ONE); /* leave one loop call */
165\& }
166.Ve
167.PP
168.Vb 4
169\& int
170\& main (void)
171\& {
172\& struct ev_loop *loop = ev_default_loop (0);
173.Ve
174.PP
175.Vb 3
176\& /* initialise an io watcher, then start it */
177\& ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
178\& ev_io_start (loop, &stdin_watcher);
179.Ve
180.PP
181.Vb 3
182\& /* simple non-repeating 5.5 second timeout */
183\& ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.);
184\& ev_timer_start (loop, &timeout_watcher);
185.Ve
186.PP
187.Vb 2
188\& /* loop till timeout or data ready */
189\& ev_loop (loop, 0);
190.Ve
191.PP
192.Vb 2
193\& return 0;
194\& }
139.Ve 195.Ve
140.SH "DESCRIPTION" 196.SH "DESCRIPTION"
141.IX Header "DESCRIPTION" 197.IX Header "DESCRIPTION"
142Libev is an event loop: you register interest in certain events (such as a 198Libev is an event loop: you register interest in certain events (such as a
143file descriptor being readable or a timeout occuring), and it will manage 199file descriptor being readable or a timeout occuring), and it will manage
240might be supported on the current system, you would need to look at 296might be supported on the current system, you would need to look at
241\&\f(CW\*(C`ev_embeddable_backends () & ev_supported_backends ()\*(C'\fR, likewise for 297\&\f(CW\*(C`ev_embeddable_backends () & ev_supported_backends ()\*(C'\fR, likewise for
242recommended ones. 298recommended ones.
243.Sp 299.Sp
244See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. 300See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info.
245.IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4 301.IP "ev_set_allocator (void *(*cb)(void *ptr, size_t size))" 4
246.IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))" 302.IX Item "ev_set_allocator (void *(*cb)(void *ptr, size_t size))"
247Sets the allocation function to use (the prototype is similar to the 303Sets the allocation function to use (the prototype and semantics are
248realloc C function, the semantics are identical). It is used to allocate 304identical to the realloc C function). It is used to allocate and free
249and free memory (no surprises here). If it returns zero when memory 305memory (no surprises here). If it returns zero when memory needs to be
250needs to be allocated, the library might abort or take some potentially 306allocated, the library might abort or take some potentially destructive
251destructive action. The default is your system realloc function. 307action. The default is your system realloc function.
252.Sp 308.Sp
253You could override this function in high-availability programs to, say, 309You could override this function in high-availability programs to, say,
254free some memory if it cannot allocate memory, to use a special allocator, 310free some memory if it cannot allocate memory, to use a special allocator,
255or even to sleep a while and retry until some memory is available. 311or even to sleep a while and retry until some memory is available.
256.Sp 312.Sp
257Example: replace the libev allocator with one that waits a bit and then 313Example: replace the libev allocator with one that waits a bit and then
258retries: better than mine). 314retries: better than mine).
259.Sp 315.Sp
260.Vb 6 316.Vb 6
261\& static void * 317\& static void *
262\& persistent_realloc (void *ptr, long size) 318\& persistent_realloc (void *ptr, size_t size)
263\& { 319\& {
264\& for (;;) 320\& for (;;)
265\& { 321\& {
266\& void *newptr = realloc (ptr, size); 322\& void *newptr = realloc (ptr, size);
267.Ve 323.Ve
2118.IP "\s-1EV_MINIMAL\s0" 4 2174.IP "\s-1EV_MINIMAL\s0" 4
2119.IX Item "EV_MINIMAL" 2175.IX Item "EV_MINIMAL"
2120If you need to shave off some kilobytes of code at the expense of some 2176If you need to shave off some kilobytes of code at the expense of some
2121speed, define this symbol to \f(CW1\fR. Currently only used for gcc to override 2177speed, define this symbol to \f(CW1\fR. Currently only used for gcc to override
2122some inlining decisions, saves roughly 30% codesize of amd64. 2178some inlining decisions, saves roughly 30% codesize of amd64.
2179.IP "\s-1EV_PID_HASHSIZE\s0" 4
2180.IX Item "EV_PID_HASHSIZE"
2181\&\f(CW\*(C`ev_child\*(C'\fR watchers use a small hash table to distribute workload by
2182pid. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), usually more
2183than enough. If you need to manage thousands of children you might want to
2184increase this value.
2123.IP "\s-1EV_COMMON\s0" 4 2185.IP "\s-1EV_COMMON\s0" 4
2124.IX Item "EV_COMMON" 2186.IX Item "EV_COMMON"
2125By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining 2187By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining
2126this macro to a something else you can include more and other types of 2188this macro to a something else you can include more and other types of
2127members. You have to define it each time you include one of the files, 2189members. You have to define it each time you include one of the files,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines