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

Comparing libev/ev.pod (file contents):
Revision 1.184 by root, Tue Sep 23 09:11:14 2008 UTC vs.
Revision 1.189 by root, Tue Sep 30 19:33:33 2008 UTC

214C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for 214C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for
215recommended ones. 215recommended ones.
216 216
217See the description of C<ev_embed> watchers for more info. 217See the description of C<ev_embed> watchers for more info.
218 218
219=item ev_set_allocator (void *(*cb)(void *ptr, long size)) 219=item ev_set_allocator (void *(*cb)(void *ptr, long size)) [NOT REENTRANT]
220 220
221Sets the allocation function to use (the prototype is similar - the 221Sets the allocation function to use (the prototype is similar - the
222semantics are identical to the C<realloc> C89/SuS/POSIX function). It is 222semantics are identical to the C<realloc> C89/SuS/POSIX function). It is
223used to allocate and free memory (no surprises here). If it returns zero 223used to allocate and free memory (no surprises here). If it returns zero
224when memory needs to be allocated (C<size != 0>), the library might abort 224when memory needs to be allocated (C<size != 0>), the library might abort
250 } 250 }
251 251
252 ... 252 ...
253 ev_set_allocator (persistent_realloc); 253 ev_set_allocator (persistent_realloc);
254 254
255=item ev_set_syserr_cb (void (*cb)(const char *msg)); 255=item ev_set_syserr_cb (void (*cb)(const char *msg)); [NOT REENTRANT]
256 256
257Set the callback function to call on a retryable system call error (such 257Set the callback function to call on a retryable system call error (such
258as failed select, poll, epoll_wait). The message is a printable string 258as failed select, poll, epoll_wait). The message is a printable string
259indicating the system call or subsystem causing the problem. If this 259indicating the system call or subsystem causing the problem. If this
260callback is set, then libev will expect it to remedy the situation, no 260callback is set, then libev will expect it to remedy the situation, no
1625 1625
1626=back 1626=back
1627 1627
1628=head3 Examples 1628=head3 Examples
1629 1629
1630Example: Try to exit cleanly on SIGINT and SIGTERM. 1630Example: Try to exit cleanly on SIGINT.
1631 1631
1632 static void 1632 static void
1633 sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents) 1633 sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents)
1634 { 1634 {
1635 ev_unloop (loop, EVUNLOOP_ALL); 1635 ev_unloop (loop, EVUNLOOP_ALL);
1636 } 1636 }
1637 1637
1638 struct ev_signal signal_watcher; 1638 struct ev_signal signal_watcher;
1639 ev_signal_init (&signal_watcher, sigint_cb, SIGINT); 1639 ev_signal_init (&signal_watcher, sigint_cb, SIGINT);
1640 ev_signal_start (loop, &sigint_cb); 1640 ev_signal_start (loop, &signal_watcher);
1641 1641
1642 1642
1643=head2 C<ev_child> - watch out for process status changes 1643=head2 C<ev_child> - watch out for process status changes
1644 1644
1645Child watchers trigger when your process receives a SIGCHLD in response to 1645Child watchers trigger when your process receives a SIGCHLD in response to
2242So when you want to use this feature you will always have to be prepared 2242So when you want to use this feature you will always have to be prepared
2243that you cannot get an embeddable loop. The recommended way to get around 2243that you cannot get an embeddable loop. The recommended way to get around
2244this is to have a separate variables for your embeddable loop, try to 2244this is to have a separate variables for your embeddable loop, try to
2245create it, and if that fails, use the normal loop for everything. 2245create it, and if that fails, use the normal loop for everything.
2246 2246
2247=head3 C<ev_embed> and fork
2248
2249While the C<ev_embed> watcher is running, forks in the embedding loop will
2250automatically be applied to the embedded loop as well, so no special
2251fork handling is required in that case. When the watcher is not running,
2252however, it is still the task of the libev user to call C<ev_loop_fork ()>
2253as applicable.
2254
2247=head3 Watcher-Specific Functions and Data Members 2255=head3 Watcher-Specific Functions and Data Members
2248 2256
2249=over 4 2257=over 4
2250 2258
2251=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) 2259=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)
3241definition and a statement, respectively. See the F<ev.h> header file for 3249definition and a statement, respectively. See the F<ev.h> header file for
3242their default definitions. One possible use for overriding these is to 3250their default definitions. One possible use for overriding these is to
3243avoid the C<struct ev_loop *> as first argument in all cases, or to use 3251avoid the C<struct ev_loop *> as first argument in all cases, or to use
3244method calls instead of plain function calls in C++. 3252method calls instead of plain function calls in C++.
3245 3253
3254=back
3255
3246=head2 EXPORTED API SYMBOLS 3256=head2 EXPORTED API SYMBOLS
3247 3257
3248If you need to re-export the API (e.g. via a DLL) and you need a list of 3258If you need to re-export the API (e.g. via a DLL) and you need a list of
3249exported symbols, you can use the provided F<Symbol.*> files which list 3259exported symbols, you can use the provided F<Symbol.*> files which list
3250all public symbols, one per line: 3260all public symbols, one per line:
3296And a F<ev_cpp.C> implementation file that contains libev proper and is compiled: 3306And a F<ev_cpp.C> implementation file that contains libev proper and is compiled:
3297 3307
3298 #include "ev_cpp.h" 3308 #include "ev_cpp.h"
3299 #include "ev.c" 3309 #include "ev.c"
3300 3310
3311=head1 INTERACTION WITH OTHER PROGRAMS OR LIBRARIES
3301 3312
3302=head1 THREADS AND COROUTINES 3313=head2 THREADS AND COROUTINES
3303 3314
3304=head2 THREADS 3315=head3 THREADS
3305 3316
3306Libev itself is thread-safe (unless the opposite is specifically 3317All libev functions are reentrant and thread-safe unless explicitly
3307documented for a function), but it uses no locking itself. This means that 3318documented otherwise, but it uses no locking itself. This means that you
3308you can use as many loops as you want in parallel, as long as only one 3319can use as many loops as you want in parallel, as long as there are no
3309thread ever calls into one libev function with the same loop parameter: 3320concurrent calls into any libev function with the same loop parameter
3321(C<ev_default_*> calls have an implicit default loop parameter, of
3310libev guarantees that different event loops share no data structures that 3322course): libev guarantees that different event loops share no data
3311need locking. 3323structures that need any locking.
3312 3324
3313Or to put it differently: calls with different loop parameters can be done 3325Or to put it differently: calls with different loop parameters can be done
3314concurrently from multiple threads, calls with the same loop parameter 3326concurrently from multiple threads, calls with the same loop parameter
3315must be done serially (but can be done from different threads, as long as 3327must be done serially (but can be done from different threads, as long as
3316only one thread ever is inside a call at any point in time, e.g. by using 3328only one thread ever is inside a call at any point in time, e.g. by using
3317a mutex per loop). 3329a mutex per loop).
3318 3330
3319Specifically to support threads (and signal handlers), libev implements 3331Specifically to support threads (and signal handlers), libev implements
3320so-called C<ev_async> watchers, which allow some limited form of 3332so-called C<ev_async> watchers, which allow some limited form of
3321concurrency on the same event loop. 3333concurrency on the same event loop, namely waking it up "from the
3334outside".
3322 3335
3323If you want to know which design (one loop, locking, or multiple loops 3336If you want to know which design (one loop, locking, or multiple loops
3324without or something else still) is best for your problem, then I cannot 3337without or something else still) is best for your problem, then I cannot
3325help you. I can give some generic advice however: 3338help you, but here is some generic advice:
3326 3339
3327=over 4 3340=over 4
3328 3341
3329=item * most applications have a main thread: use the default libev loop 3342=item * most applications have a main thread: use the default libev loop
3330in that thread, or create a separate thread running only the default loop. 3343in that thread, or create a separate thread running only the default loop.
3354default loop and triggering an C<ev_async> watcher from the default loop 3367default loop and triggering an C<ev_async> watcher from the default loop
3355watcher callback into the event loop interested in the signal. 3368watcher callback into the event loop interested in the signal.
3356 3369
3357=back 3370=back
3358 3371
3359=head2 COROUTINES 3372=head3 COROUTINES
3360 3373
3361Libev is much more accommodating to coroutines ("cooperative threads"): 3374Libev is much more accommodating to coroutines ("cooperative threads"):
3362libev fully supports nesting calls to it's functions from different 3375libev fully supports nesting calls to it's functions from different
3363coroutines (e.g. you can call C<ev_loop> on the same loop from two 3376coroutines (e.g. you can call C<ev_loop> on the same loop from two
3364different coroutines and switch freely between both coroutines running the 3377different coroutines and switch freely between both coroutines running the
3366you must not do this from C<ev_periodic> reschedule callbacks. 3379you must not do this from C<ev_periodic> reschedule callbacks.
3367 3380
3368Care has been taken to ensure that libev does not keep local state inside 3381Care has been taken to ensure that libev does not keep local state inside
3369C<ev_loop>, and other calls do not usually allow coroutine switches. 3382C<ev_loop>, and other calls do not usually allow coroutine switches.
3370 3383
3384=head2 COMPILER WARNINGS
3385
3386Depending on your compiler and compiler settings, you might get no or a
3387lot of warnings when compiling libev code. Some people are apparently
3388scared by this.
3389
3390However, these are unavoidable for many reasons. For one, each compiler
3391has different warnings, and each user has different tastes regarding
3392warning options. "Warn-free" code therefore cannot be a goal except when
3393targeting a specific compiler and compiler-version.
3394
3395Another reason is that some compiler warnings require elaborate
3396workarounds, or other changes to the code that make it less clear and less
3397maintainable.
3398
3399And of course, some compiler warnings are just plain stupid, or simply
3400wrong (because they don't actually warn about the condition their message
3401seems to warn about). For example, certain older gcc versions had some
3402warnings that resulted an extreme number of false positives. These have
3403been fixed, but some people still insist on making code warn-free with
3404such buggy versions.
3405
3406While libev is written to generate as few warnings as possible,
3407"warn-free" code is not a goal, and it is recommended not to build libev
3408with any compiler warnings enabled unless you are prepared to cope with
3409them (e.g. by ignoring them). Remember that warnings are just that:
3410warnings, not errors, or proof of bugs.
3411
3412
3413=head1 VALGRIND
3414
3415Valgrind has a special section here because it is a popular tool that is
3416highly useful. Unfortunately, valgrind reports are very hard to interpret.
3417
3418If you think you found a bug (memory leak, uninitialised data access etc.)
3419in libev, then check twice: If valgrind reports something like:
3420
3421 ==2274== definitely lost: 0 bytes in 0 blocks.
3422 ==2274== possibly lost: 0 bytes in 0 blocks.
3423 ==2274== still reachable: 256 bytes in 1 blocks.
3424
3425Then there is no memory leak, just as memory accounted to global variables
3426is not a memleak - the memory is still being refernced, and didn't leak.
3427
3428Similarly, under some circumstances, valgrind might report kernel bugs
3429as if it were a bug in libev (e.g. in realloc or in the poll backend,
3430although an acceptable workaround has been found here), or it might be
3431confused.
3432
3433Keep in mind that valgrind is a very good tool, but only a tool. Don't
3434make it into some kind of religion.
3435
3436If you are unsure about something, feel free to contact the mailing list
3437with the full valgrind report and an explanation on why you think this
3438is a bug in libev (best check the archives, too :). However, don't be
3439annoyed when you get a brisk "this is no bug" answer and take the chance
3440of learning how to interpret valgrind properly.
3441
3442If you need, for some reason, empty reports from valgrind for your project
3443I suggest using suppression lists.
3444
3445
3371 3446
3372=head1 COMPLEXITIES 3447=head1 COMPLEXITIES
3373 3448
3374In this section the complexities of (many of) the algorithms used inside 3449In this section the complexities of (many of) the algorithms used inside
3375libev will be explained. For complexity discussions about backends see the 3450libev will be explained. For complexity discussions about backends see the
3437involves iterating over all running async watchers or all signal numbers. 3512involves iterating over all running async watchers or all signal numbers.
3438 3513
3439=back 3514=back
3440 3515
3441 3516
3517=head1 PORTABILITY
3518
3442=head1 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS 3519=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS
3443 3520
3444Win32 doesn't support any of the standards (e.g. POSIX) that libev 3521Win32 doesn't support any of the standards (e.g. POSIX) that libev
3445requires, and its I/O model is fundamentally incompatible with the POSIX 3522requires, and its I/O model is fundamentally incompatible with the POSIX
3446model. Libev still offers limited functionality on this platform in 3523model. Libev still offers limited functionality on this platform in
3447the form of the C<EVBACKEND_SELECT> backend, and only supports socket 3524the form of the C<EVBACKEND_SELECT> backend, and only supports socket
3534wrap all I/O functions and provide your own fd management, but the cost of 3611wrap all I/O functions and provide your own fd management, but the cost of
3535calling select (O(n²)) will likely make this unworkable. 3612calling select (O(n²)) will likely make this unworkable.
3536 3613
3537=back 3614=back
3538 3615
3539
3540=head1 PORTABILITY REQUIREMENTS 3616=head2 PORTABILITY REQUIREMENTS
3541 3617
3542In addition to a working ISO-C implementation, libev relies on a few 3618In addition to a working ISO-C implementation and of course the
3543additional extensions: 3619backend-specific APIs, libev relies on a few additional extensions:
3544 3620
3545=over 4 3621=over 4
3546 3622
3547=item C<void (*)(ev_watcher_type *, int revents)> must have compatible 3623=item C<void (*)(ev_watcher_type *, int revents)> must have compatible
3548calling conventions regardless of C<ev_watcher_type *>. 3624calling conventions regardless of C<ev_watcher_type *>.
3573except the initial one, and run the default loop in the initial thread as 3649except the initial one, and run the default loop in the initial thread as
3574well. 3650well.
3575 3651
3576=item C<long> must be large enough for common memory allocation sizes 3652=item C<long> must be large enough for common memory allocation sizes
3577 3653
3578To improve portability and simplify using libev, libev uses C<long> 3654To improve portability and simplify its API, libev uses C<long> internally
3579internally instead of C<size_t> when allocating its data structures. On 3655instead of C<size_t> when allocating its data structures. On non-POSIX
3580non-POSIX systems (Microsoft...) this might be unexpectedly low, but 3656systems (Microsoft...) this might be unexpectedly low, but is still at
3581is still at least 31 bits everywhere, which is enough for hundreds of 3657least 31 bits everywhere, which is enough for hundreds of millions of
3582millions of watchers. 3658watchers.
3583 3659
3584=item C<double> must hold a time value in seconds with enough accuracy 3660=item C<double> must hold a time value in seconds with enough accuracy
3585 3661
3586The type C<double> is used to represent timestamps. It is required to 3662The type C<double> is used to represent timestamps. It is required to
3587have at least 51 bits of mantissa (and 9 bits of exponent), which is good 3663have at least 51 bits of mantissa (and 9 bits of exponent), which is good
3591=back 3667=back
3592 3668
3593If you know of other additional requirements drop me a note. 3669If you know of other additional requirements drop me a note.
3594 3670
3595 3671
3596=head1 COMPILER WARNINGS
3597
3598Depending on your compiler and compiler settings, you might get no or a
3599lot of warnings when compiling libev code. Some people are apparently
3600scared by this.
3601
3602However, these are unavoidable for many reasons. For one, each compiler
3603has different warnings, and each user has different tastes regarding
3604warning options. "Warn-free" code therefore cannot be a goal except when
3605targeting a specific compiler and compiler-version.
3606
3607Another reason is that some compiler warnings require elaborate
3608workarounds, or other changes to the code that make it less clear and less
3609maintainable.
3610
3611And of course, some compiler warnings are just plain stupid, or simply
3612wrong (because they don't actually warn about the condition their message
3613seems to warn about).
3614
3615While libev is written to generate as few warnings as possible,
3616"warn-free" code is not a goal, and it is recommended not to build libev
3617with any compiler warnings enabled unless you are prepared to cope with
3618them (e.g. by ignoring them). Remember that warnings are just that:
3619warnings, not errors, or proof of bugs.
3620
3621
3622=head1 VALGRIND
3623
3624Valgrind has a special section here because it is a popular tool that is
3625highly useful, but valgrind reports are very hard to interpret.
3626
3627If you think you found a bug (memory leak, uninitialised data access etc.)
3628in libev, then check twice: If valgrind reports something like:
3629
3630 ==2274== definitely lost: 0 bytes in 0 blocks.
3631 ==2274== possibly lost: 0 bytes in 0 blocks.
3632 ==2274== still reachable: 256 bytes in 1 blocks.
3633
3634Then there is no memory leak. Similarly, under some circumstances,
3635valgrind might report kernel bugs as if it were a bug in libev, or it
3636might be confused (it is a very good tool, but only a tool).
3637
3638If you are unsure about something, feel free to contact the mailing list
3639with the full valgrind report and an explanation on why you think this is
3640a bug in libev. However, don't be annoyed when you get a brisk "this is
3641no bug" answer and take the chance of learning how to interpret valgrind
3642properly.
3643
3644If you need, for some reason, empty reports from valgrind for your project
3645I suggest using suppression lists.
3646
3647
3648=head1 AUTHOR 3672=head1 AUTHOR
3649 3673
3650Marc Lehmann <libev@schmorp.de>. 3674Marc Lehmann <libev@schmorp.de>.
3651 3675

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines