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

Comparing libev/ev.pod (file contents):
Revision 1.183 by root, Tue Sep 23 08:37:38 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
2233when you fork, you not only have to call C<ev_loop_fork> on both loops, 2233when you fork, you not only have to call C<ev_loop_fork> on both loops,
2234but you will also have to stop and restart any C<ev_embed> watchers 2234but you will also have to stop and restart any C<ev_embed> watchers
2235yourself - but you can use a fork watcher to handle this automatically, 2235yourself - but you can use a fork watcher to handle this automatically,
2236and future versions of libev might do just that. 2236and future versions of libev might do just that.
2237 2237
2238Unfortunately, not all backends are embeddable, only the ones returned by 2238Unfortunately, not all backends are embeddable: only the ones returned by
2239C<ev_embeddable_backends> are, which, unfortunately, does not include any 2239C<ev_embeddable_backends> are, which, unfortunately, does not include any
2240portable one. 2240portable one.
2241 2241
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
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.
2246 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
2368is that the author does not know of a simple (or any) algorithm for a 2376is that the author does not know of a simple (or any) algorithm for a
2369multiple-writer-single-reader queue that works in all cases and doesn't 2377multiple-writer-single-reader queue that works in all cases and doesn't
2370need elaborate support such as pthreads. 2378need elaborate support such as pthreads.
2371 2379
2372That means that if you want to queue data, you have to provide your own 2380That means that if you want to queue data, you have to provide your own
2373queue. But at least I can tell you would implement locking around your 2381queue. But at least I can tell you how to implement locking around your
2374queue: 2382queue:
2375 2383
2376=over 4 2384=over 4
2377 2385
2378=item queueing from a signal handler context 2386=item queueing from a signal handler context
2454 2462
2455=item ev_async_init (ev_async *, callback) 2463=item ev_async_init (ev_async *, callback)
2456 2464
2457Initialises and configures the async watcher - it has no parameters of any 2465Initialises and configures the async watcher - it has no parameters of any
2458kind. There is a C<ev_asynd_set> macro, but using it is utterly pointless, 2466kind. There is a C<ev_asynd_set> macro, but using it is utterly pointless,
2459believe me. 2467trust me.
2460 2468
2461=item ev_async_send (loop, ev_async *) 2469=item ev_async_send (loop, ev_async *)
2462 2470
2463Sends/signals/activates the given C<ev_async> watcher, that is, feeds 2471Sends/signals/activates the given C<ev_async> watcher, that is, feeds
2464an C<EV_ASYNC> event on the watcher into the event loop. Unlike 2472an C<EV_ASYNC> event on the watcher into the event loop. Unlike
2465C<ev_feed_event>, this call is safe to do in other threads, signal or 2473C<ev_feed_event>, this call is safe to do from other threads, signal or
2466similar contexts (see the discussion of C<EV_ATOMIC_T> in the embedding 2474similar contexts (see the discussion of C<EV_ATOMIC_T> in the embedding
2467section below on what exactly this means). 2475section below on what exactly this means).
2468 2476
2469This call incurs the overhead of a system call only once per loop iteration, 2477This call incurs the overhead of a system call only once per loop iteration,
2470so while the overhead might be noticeable, it doesn't apply to repeated 2478so while the overhead might be noticeable, it doesn't apply to repeated
2676 2684
2677The prototype of the C<function> must be C<void (*)(ev::TYPE &w, int)>. 2685The prototype of the C<function> must be C<void (*)(ev::TYPE &w, int)>.
2678 2686
2679See the method-C<set> above for more details. 2687See the method-C<set> above for more details.
2680 2688
2681Example: 2689Example: Use a plain function as callback.
2682 2690
2683 static void io_cb (ev::io &w, int revents) { } 2691 static void io_cb (ev::io &w, int revents) { }
2684 iow.set <io_cb> (); 2692 iow.set <io_cb> ();
2685 2693
2686=item w->set (struct ev_loop *) 2694=item w->set (struct ev_loop *)
2724Example: Define a class with an IO and idle watcher, start one of them in 2732Example: Define a class with an IO and idle watcher, start one of them in
2725the constructor. 2733the constructor.
2726 2734
2727 class myclass 2735 class myclass
2728 { 2736 {
2729 ev::io io; void io_cb (ev::io &w, int revents); 2737 ev::io io ; void io_cb (ev::io &w, int revents);
2730 ev:idle idle void idle_cb (ev::idle &w, int revents); 2738 ev::idle idle; void idle_cb (ev::idle &w, int revents);
2731 2739
2732 myclass (int fd) 2740 myclass (int fd)
2733 { 2741 {
2734 io .set <myclass, &myclass::io_cb > (this); 2742 io .set <myclass, &myclass::io_cb > (this);
2735 idle.set <myclass, &myclass::idle_cb> (this); 2743 idle.set <myclass, &myclass::idle_cb> (this);
2751=item Perl 2759=item Perl
2752 2760
2753The EV module implements the full libev API and is actually used to test 2761The EV module implements the full libev API and is actually used to test
2754libev. EV is developed together with libev. Apart from the EV core module, 2762libev. EV is developed together with libev. Apart from the EV core module,
2755there are additional modules that implement libev-compatible interfaces 2763there are additional modules that implement libev-compatible interfaces
2756to C<libadns> (C<EV::ADNS>), C<Net::SNMP> (C<Net::SNMP::EV>) and the 2764to C<libadns> (C<EV::ADNS>, but C<AnyEvent::DNS> is preferred nowadays),
2757C<libglib> event core (C<Glib::EV> and C<EV::Glib>). 2765C<Net::SNMP> (C<Net::SNMP::EV>) and the C<libglib> event core (C<Glib::EV>
2766and C<EV::Glib>).
2758 2767
2759It can be found and installed via CPAN, its homepage is at 2768It can be found and installed via CPAN, its homepage is at
2760L<http://software.schmorp.de/pkg/EV>. 2769L<http://software.schmorp.de/pkg/EV>.
2761 2770
2762=item Python 2771=item Python
2941 2950
2942=head2 PREPROCESSOR SYMBOLS/MACROS 2951=head2 PREPROCESSOR SYMBOLS/MACROS
2943 2952
2944Libev can be configured via a variety of preprocessor symbols you have to 2953Libev can be configured via a variety of preprocessor symbols you have to
2945define before including any of its files. The default in the absence of 2954define before including any of its files. The default in the absence of
2946autoconf is noted for every option. 2955autoconf is documented for every option.
2947 2956
2948=over 4 2957=over 4
2949 2958
2950=item EV_STANDALONE 2959=item EV_STANDALONE
2951 2960
3121When doing priority-based operations, libev usually has to linearly search 3130When doing priority-based operations, libev usually has to linearly search
3122all the priorities, so having many of them (hundreds) uses a lot of space 3131all the priorities, so having many of them (hundreds) uses a lot of space
3123and time, so using the defaults of five priorities (-2 .. +2) is usually 3132and time, so using the defaults of five priorities (-2 .. +2) is usually
3124fine. 3133fine.
3125 3134
3126If your embedding application does not need any priorities, defining these both to 3135If your embedding application does not need any priorities, defining these
3127C<0> will save some memory and CPU. 3136both to C<0> will save some memory and CPU.
3128 3137
3129=item EV_PERIODIC_ENABLE 3138=item EV_PERIODIC_ENABLE
3130 3139
3131If undefined or defined to be C<1>, then periodic timers are supported. If 3140If undefined or defined to be C<1>, then periodic timers are supported. If
3132defined to be C<0>, then they are not. Disabling them saves a few kB of 3141defined to be C<0>, then they are not. Disabling them saves a few kB of
3139code. 3148code.
3140 3149
3141=item EV_EMBED_ENABLE 3150=item EV_EMBED_ENABLE
3142 3151
3143If undefined or defined to be C<1>, then embed watchers are supported. If 3152If undefined or defined to be C<1>, then embed watchers are supported. If
3144defined to be C<0>, then they are not. 3153defined to be C<0>, then they are not. Embed watchers rely on most other
3154watcher types, which therefore must not be disabled.
3145 3155
3146=item EV_STAT_ENABLE 3156=item EV_STAT_ENABLE
3147 3157
3148If undefined or defined to be C<1>, then stat watchers are supported. If 3158If undefined or defined to be C<1>, then stat watchers are supported. If
3149defined to be C<0>, then they are not. 3159defined to be C<0>, then they are not.
3181two). 3191two).
3182 3192
3183=item EV_USE_4HEAP 3193=item EV_USE_4HEAP
3184 3194
3185Heaps are not very cache-efficient. To improve the cache-efficiency of the 3195Heaps are not very cache-efficient. To improve the cache-efficiency of the
3186timer and periodics heap, libev uses a 4-heap when this symbol is defined 3196timer and periodics heaps, libev uses a 4-heap when this symbol is defined
3187to C<1>. The 4-heap uses more complicated (longer) code but has 3197to C<1>. The 4-heap uses more complicated (longer) code but has noticeably
3188noticeably faster performance with many (thousands) of watchers. 3198faster performance with many (thousands) of watchers.
3189 3199
3190The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0> 3200The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0>
3191(disabled). 3201(disabled).
3192 3202
3193=item EV_HEAP_CACHE_AT 3203=item EV_HEAP_CACHE_AT
3194 3204
3195Heaps are not very cache-efficient. To improve the cache-efficiency of the 3205Heaps are not very cache-efficient. To improve the cache-efficiency of the
3196timer and periodics heap, libev can cache the timestamp (I<at>) within 3206timer and periodics heaps, libev can cache the timestamp (I<at>) within
3197the heap structure (selected by defining C<EV_HEAP_CACHE_AT> to C<1>), 3207the heap structure (selected by defining C<EV_HEAP_CACHE_AT> to C<1>),
3198which uses 8-12 bytes more per watcher and a few hundred bytes more code, 3208which uses 8-12 bytes more per watcher and a few hundred bytes more code,
3199but avoids random read accesses on heap changes. This improves performance 3209but avoids random read accesses on heap changes. This improves performance
3200noticeably with with many (hundreds) of watchers. 3210noticeably with many (hundreds) of watchers.
3201 3211
3202The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0> 3212The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0>
3203(disabled). 3213(disabled).
3204 3214
3205=item EV_VERIFY 3215=item EV_VERIFY
3211called once per loop, which can slow down libev. If set to C<3>, then the 3221called once per loop, which can slow down libev. If set to C<3>, then the
3212verification code will be called very frequently, which will slow down 3222verification code will be called very frequently, which will slow down
3213libev considerably. 3223libev considerably.
3214 3224
3215The default is C<1>, unless C<EV_MINIMAL> is set, in which case it will be 3225The default is C<1>, unless C<EV_MINIMAL> is set, in which case it will be
3216C<0.> 3226C<0>.
3217 3227
3218=item EV_COMMON 3228=item EV_COMMON
3219 3229
3220By default, all watchers have a C<void *data> member. By redefining 3230By default, all watchers have a C<void *data> member. By redefining
3221this macro to a something else you can include more and other types of 3231this macro to a something else you can include more and other types of
3238and the way callbacks are invoked and set. Must expand to a struct member 3248and the way callbacks are invoked and set. Must expand to a struct member
3239definition 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
3240their default definitions. One possible use for overriding these is to 3250their default definitions. One possible use for overriding these is to
3241avoid 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
3242method calls instead of plain function calls in C++. 3252method calls instead of plain function calls in C++.
3253
3254=back
3243 3255
3244=head2 EXPORTED API SYMBOLS 3256=head2 EXPORTED API SYMBOLS
3245 3257
3246If 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
3247exported symbols, you can use the provided F<Symbol.*> files which list 3259exported symbols, you can use the provided F<Symbol.*> files which list
3294And 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:
3295 3307
3296 #include "ev_cpp.h" 3308 #include "ev_cpp.h"
3297 #include "ev.c" 3309 #include "ev.c"
3298 3310
3311=head1 INTERACTION WITH OTHER PROGRAMS OR LIBRARIES
3299 3312
3300=head1 THREADS AND COROUTINES 3313=head2 THREADS AND COROUTINES
3301 3314
3302=head2 THREADS 3315=head3 THREADS
3303 3316
3304Libev itself is thread-safe (unless the opposite is specifically 3317All libev functions are reentrant and thread-safe unless explicitly
3305documented for a function), but it uses no locking itself. This means that 3318documented otherwise, but it uses no locking itself. This means that you
3306you 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
3307thread 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
3308libev guarentees that different event loops share no data structures that 3322course): libev guarantees that different event loops share no data
3309need locking. 3323structures that need any locking.
3310 3324
3311Or 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
3312concurrently from multiple threads, calls with the same loop parameter 3326concurrently from multiple threads, calls with the same loop parameter
3313must 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
3314only 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
3315a mutex per loop). 3329a mutex per loop).
3316 3330
3317Specifically to support threads (and signal handlers), libev implements 3331Specifically to support threads (and signal handlers), libev implements
3318so-called C<ev_async> watchers, which allow some limited form of 3332so-called C<ev_async> watchers, which allow some limited form of
3319concurrency on the same event loop. 3333concurrency on the same event loop, namely waking it up "from the
3334outside".
3320 3335
3321If 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
3322without 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
3323help you. I can give some generic advice however: 3338help you, but here is some generic advice:
3324 3339
3325=over 4 3340=over 4
3326 3341
3327=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
3328in 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.
3352default 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
3353watcher callback into the event loop interested in the signal. 3368watcher callback into the event loop interested in the signal.
3354 3369
3355=back 3370=back
3356 3371
3357=head2 COROUTINES 3372=head3 COROUTINES
3358 3373
3359Libev is much more accommodating to coroutines ("cooperative threads"): 3374Libev is much more accommodating to coroutines ("cooperative threads"):
3360libev fully supports nesting calls to it's functions from different 3375libev fully supports nesting calls to it's functions from different
3361coroutines (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
3362different coroutines and switch freely between both coroutines running the 3377different coroutines and switch freely between both coroutines running the
3364you must not do this from C<ev_periodic> reschedule callbacks. 3379you must not do this from C<ev_periodic> reschedule callbacks.
3365 3380
3366Care 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
3367C<ev_loop>, and other calls do not usually allow coroutine switches. 3382C<ev_loop>, and other calls do not usually allow coroutine switches.
3368 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
3369 3446
3370=head1 COMPLEXITIES 3447=head1 COMPLEXITIES
3371 3448
3372In this section the complexities of (many of) the algorithms used inside 3449In this section the complexities of (many of) the algorithms used inside
3373libev will be explained. For complexity discussions about backends see the 3450libev will be explained. For complexity discussions about backends see the
3420=item Priority handling: O(number_of_priorities) 3497=item Priority handling: O(number_of_priorities)
3421 3498
3422Priorities are implemented by allocating some space for each 3499Priorities are implemented by allocating some space for each
3423priority. When doing priority-based operations, libev usually has to 3500priority. When doing priority-based operations, libev usually has to
3424linearly search all the priorities, but starting/stopping and activating 3501linearly search all the priorities, but starting/stopping and activating
3425watchers becomes O(1) w.r.t. priority handling. 3502watchers becomes O(1) with respect to priority handling.
3426 3503
3427=item Sending an ev_async: O(1) 3504=item Sending an ev_async: O(1)
3428 3505
3429=item Processing ev_async_send: O(number_of_async_watchers) 3506=item Processing ev_async_send: O(number_of_async_watchers)
3430 3507
3435involves iterating over all running async watchers or all signal numbers. 3512involves iterating over all running async watchers or all signal numbers.
3436 3513
3437=back 3514=back
3438 3515
3439 3516
3517=head1 PORTABILITY
3518
3440=head1 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS 3519=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS
3441 3520
3442Win32 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
3443requires, and its I/O model is fundamentally incompatible with the POSIX 3522requires, and its I/O model is fundamentally incompatible with the POSIX
3444model. Libev still offers limited functionality on this platform in 3523model. Libev still offers limited functionality on this platform in
3445the form of the C<EVBACKEND_SELECT> backend, and only supports socket 3524the form of the C<EVBACKEND_SELECT> backend, and only supports socket
3456 3535
3457Not a libev limitation but worth mentioning: windows apparently doesn't 3536Not a libev limitation but worth mentioning: windows apparently doesn't
3458accept large writes: instead of resulting in a partial write, windows will 3537accept large writes: instead of resulting in a partial write, windows will
3459either accept everything or return C<ENOBUFS> if the buffer is too large, 3538either accept everything or return C<ENOBUFS> if the buffer is too large,
3460so make sure you only write small amounts into your sockets (less than a 3539so make sure you only write small amounts into your sockets (less than a
3461megabyte seems safe, but thsi apparently depends on the amount of memory 3540megabyte seems safe, but this apparently depends on the amount of memory
3462available). 3541available).
3463 3542
3464Due to the many, low, and arbitrary limits on the win32 platform and 3543Due to the many, low, and arbitrary limits on the win32 platform and
3465the abysmal performance of winsockets, using a large number of sockets 3544the abysmal performance of winsockets, using a large number of sockets
3466is not recommended (and not reasonable). If your program needs to use 3545is not recommended (and not reasonable). If your program needs to use
3477 #define EV_SELECT_IS_WINSOCKET 1 /* configure libev for windows select */ 3556 #define EV_SELECT_IS_WINSOCKET 1 /* configure libev for windows select */
3478 3557
3479 #include "ev.h" 3558 #include "ev.h"
3480 3559
3481And compile the following F<evwrap.c> file into your project (make sure 3560And compile the following F<evwrap.c> file into your project (make sure
3482you do I<not> compile the F<ev.c> or any other embedded soruce files!): 3561you do I<not> compile the F<ev.c> or any other embedded source files!):
3483 3562
3484 #include "evwrap.h" 3563 #include "evwrap.h"
3485 #include "ev.c" 3564 #include "ev.c"
3486 3565
3487=over 4 3566=over 4
3532wrap 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
3533calling select (O(n²)) will likely make this unworkable. 3612calling select (O(n²)) will likely make this unworkable.
3534 3613
3535=back 3614=back
3536 3615
3537
3538=head1 PORTABILITY REQUIREMENTS 3616=head2 PORTABILITY REQUIREMENTS
3539 3617
3540In addition to a working ISO-C implementation, libev relies on a few 3618In addition to a working ISO-C implementation and of course the
3541additional extensions: 3619backend-specific APIs, libev relies on a few additional extensions:
3542 3620
3543=over 4 3621=over 4
3544 3622
3545=item C<void (*)(ev_watcher_type *, int revents)> must have compatible 3623=item C<void (*)(ev_watcher_type *, int revents)> must have compatible
3546calling conventions regardless of C<ev_watcher_type *>. 3624calling conventions regardless of C<ev_watcher_type *>.
3552calls them using an C<ev_watcher *> internally. 3630calls them using an C<ev_watcher *> internally.
3553 3631
3554=item C<sig_atomic_t volatile> must be thread-atomic as well 3632=item C<sig_atomic_t volatile> must be thread-atomic as well
3555 3633
3556The type C<sig_atomic_t volatile> (or whatever is defined as 3634The type C<sig_atomic_t volatile> (or whatever is defined as
3557C<EV_ATOMIC_T>) must be atomic w.r.t. accesses from different 3635C<EV_ATOMIC_T>) must be atomic with respect to accesses from different
3558threads. This is not part of the specification for C<sig_atomic_t>, but is 3636threads. This is not part of the specification for C<sig_atomic_t>, but is
3559believed to be sufficiently portable. 3637believed to be sufficiently portable.
3560 3638
3561=item C<sigprocmask> must work in a threaded environment 3639=item C<sigprocmask> must work in a threaded environment
3562 3640
3571except 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
3572well. 3650well.
3573 3651
3574=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
3575 3653
3576To improve portability and simplify using libev, libev uses C<long> 3654To improve portability and simplify its API, libev uses C<long> internally
3577internally instead of C<size_t> when allocating its data structures. On 3655instead of C<size_t> when allocating its data structures. On non-POSIX
3578non-POSIX systems (Microsoft...) this might be unexpectedly low, but 3656systems (Microsoft...) this might be unexpectedly low, but is still at
3579is still at least 31 bits everywhere, which is enough for hundreds of 3657least 31 bits everywhere, which is enough for hundreds of millions of
3580millions of watchers. 3658watchers.
3581 3659
3582=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
3583 3661
3584The 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
3585have 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
3589=back 3667=back
3590 3668
3591If you know of other additional requirements drop me a note. 3669If you know of other additional requirements drop me a note.
3592 3670
3593 3671
3594=head1 COMPILER WARNINGS
3595
3596Depending on your compiler and compiler settings, you might get no or a
3597lot of warnings when compiling libev code. Some people are apparently
3598scared by this.
3599
3600However, these are unavoidable for many reasons. For one, each compiler
3601has different warnings, and each user has different tastes regarding
3602warning options. "Warn-free" code therefore cannot be a goal except when
3603targeting a specific compiler and compiler-version.
3604
3605Another reason is that some compiler warnings require elaborate
3606workarounds, or other changes to the code that make it less clear and less
3607maintainable.
3608
3609And of course, some compiler warnings are just plain stupid, or simply
3610wrong (because they don't actually warn about the condition their message
3611seems to warn about).
3612
3613While libev is written to generate as few warnings as possible,
3614"warn-free" code is not a goal, and it is recommended not to build libev
3615with any compiler warnings enabled unless you are prepared to cope with
3616them (e.g. by ignoring them). Remember that warnings are just that:
3617warnings, not errors, or proof of bugs.
3618
3619
3620=head1 VALGRIND
3621
3622Valgrind has a special section here because it is a popular tool that is
3623highly useful, but valgrind reports are very hard to interpret.
3624
3625If you think you found a bug (memory leak, uninitialised data access etc.)
3626in libev, then check twice: If valgrind reports something like:
3627
3628 ==2274== definitely lost: 0 bytes in 0 blocks.
3629 ==2274== possibly lost: 0 bytes in 0 blocks.
3630 ==2274== still reachable: 256 bytes in 1 blocks.
3631
3632Then there is no memory leak. Similarly, under some circumstances,
3633valgrind might report kernel bugs as if it were a bug in libev, or it
3634might be confused (it is a very good tool, but only a tool).
3635
3636If you are unsure about something, feel free to contact the mailing list
3637with the full valgrind report and an explanation on why you think this is
3638a bug in libev. However, don't be annoyed when you get a brisk "this is
3639no bug" answer and take the chance of learning how to interpret valgrind
3640properly.
3641
3642If you need, for some reason, empty reports from valgrind for your project
3643I suggest using suppression lists.
3644
3645
3646=head1 AUTHOR 3672=head1 AUTHOR
3647 3673
3648Marc Lehmann <libev@schmorp.de>. 3674Marc Lehmann <libev@schmorp.de>.
3649 3675

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines