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.184 by root, Tue Sep 23 09:11:14 2008 UTC

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
2368is that the author does not know of a simple (or any) algorithm for a 2368is 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 2369multiple-writer-single-reader queue that works in all cases and doesn't
2370need elaborate support such as pthreads. 2370need elaborate support such as pthreads.
2371 2371
2372That means that if you want to queue data, you have to provide your own 2372That 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 2373queue. But at least I can tell you how to implement locking around your
2374queue: 2374queue:
2375 2375
2376=over 4 2376=over 4
2377 2377
2378=item queueing from a signal handler context 2378=item queueing from a signal handler context
2454 2454
2455=item ev_async_init (ev_async *, callback) 2455=item ev_async_init (ev_async *, callback)
2456 2456
2457Initialises and configures the async watcher - it has no parameters of any 2457Initialises 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, 2458kind. There is a C<ev_asynd_set> macro, but using it is utterly pointless,
2459believe me. 2459trust me.
2460 2460
2461=item ev_async_send (loop, ev_async *) 2461=item ev_async_send (loop, ev_async *)
2462 2462
2463Sends/signals/activates the given C<ev_async> watcher, that is, feeds 2463Sends/signals/activates the given C<ev_async> watcher, that is, feeds
2464an C<EV_ASYNC> event on the watcher into the event loop. Unlike 2464an 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 2465C<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 2466similar contexts (see the discussion of C<EV_ATOMIC_T> in the embedding
2467section below on what exactly this means). 2467section below on what exactly this means).
2468 2468
2469This call incurs the overhead of a system call only once per loop iteration, 2469This 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 2470so while the overhead might be noticeable, it doesn't apply to repeated
2676 2676
2677The prototype of the C<function> must be C<void (*)(ev::TYPE &w, int)>. 2677The prototype of the C<function> must be C<void (*)(ev::TYPE &w, int)>.
2678 2678
2679See the method-C<set> above for more details. 2679See the method-C<set> above for more details.
2680 2680
2681Example: 2681Example: Use a plain function as callback.
2682 2682
2683 static void io_cb (ev::io &w, int revents) { } 2683 static void io_cb (ev::io &w, int revents) { }
2684 iow.set <io_cb> (); 2684 iow.set <io_cb> ();
2685 2685
2686=item w->set (struct ev_loop *) 2686=item w->set (struct ev_loop *)
2724Example: Define a class with an IO and idle watcher, start one of them in 2724Example: Define a class with an IO and idle watcher, start one of them in
2725the constructor. 2725the constructor.
2726 2726
2727 class myclass 2727 class myclass
2728 { 2728 {
2729 ev::io io; void io_cb (ev::io &w, int revents); 2729 ev::io io ; void io_cb (ev::io &w, int revents);
2730 ev:idle idle void idle_cb (ev::idle &w, int revents); 2730 ev::idle idle; void idle_cb (ev::idle &w, int revents);
2731 2731
2732 myclass (int fd) 2732 myclass (int fd)
2733 { 2733 {
2734 io .set <myclass, &myclass::io_cb > (this); 2734 io .set <myclass, &myclass::io_cb > (this);
2735 idle.set <myclass, &myclass::idle_cb> (this); 2735 idle.set <myclass, &myclass::idle_cb> (this);
2751=item Perl 2751=item Perl
2752 2752
2753The EV module implements the full libev API and is actually used to test 2753The 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, 2754libev. EV is developed together with libev. Apart from the EV core module,
2755there are additional modules that implement libev-compatible interfaces 2755there are additional modules that implement libev-compatible interfaces
2756to C<libadns> (C<EV::ADNS>), C<Net::SNMP> (C<Net::SNMP::EV>) and the 2756to C<libadns> (C<EV::ADNS>, but C<AnyEvent::DNS> is preferred nowadays),
2757C<libglib> event core (C<Glib::EV> and C<EV::Glib>). 2757C<Net::SNMP> (C<Net::SNMP::EV>) and the C<libglib> event core (C<Glib::EV>
2758and C<EV::Glib>).
2758 2759
2759It can be found and installed via CPAN, its homepage is at 2760It can be found and installed via CPAN, its homepage is at
2760L<http://software.schmorp.de/pkg/EV>. 2761L<http://software.schmorp.de/pkg/EV>.
2761 2762
2762=item Python 2763=item Python
2941 2942
2942=head2 PREPROCESSOR SYMBOLS/MACROS 2943=head2 PREPROCESSOR SYMBOLS/MACROS
2943 2944
2944Libev can be configured via a variety of preprocessor symbols you have to 2945Libev 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 2946define before including any of its files. The default in the absence of
2946autoconf is noted for every option. 2947autoconf is documented for every option.
2947 2948
2948=over 4 2949=over 4
2949 2950
2950=item EV_STANDALONE 2951=item EV_STANDALONE
2951 2952
3121When doing priority-based operations, libev usually has to linearly search 3122When doing priority-based operations, libev usually has to linearly search
3122all the priorities, so having many of them (hundreds) uses a lot of space 3123all 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 3124and time, so using the defaults of five priorities (-2 .. +2) is usually
3124fine. 3125fine.
3125 3126
3126If your embedding application does not need any priorities, defining these both to 3127If your embedding application does not need any priorities, defining these
3127C<0> will save some memory and CPU. 3128both to C<0> will save some memory and CPU.
3128 3129
3129=item EV_PERIODIC_ENABLE 3130=item EV_PERIODIC_ENABLE
3130 3131
3131If undefined or defined to be C<1>, then periodic timers are supported. If 3132If 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 3133defined to be C<0>, then they are not. Disabling them saves a few kB of
3139code. 3140code.
3140 3141
3141=item EV_EMBED_ENABLE 3142=item EV_EMBED_ENABLE
3142 3143
3143If undefined or defined to be C<1>, then embed watchers are supported. If 3144If undefined or defined to be C<1>, then embed watchers are supported. If
3144defined to be C<0>, then they are not. 3145defined to be C<0>, then they are not. Embed watchers rely on most other
3146watcher types, which therefore must not be disabled.
3145 3147
3146=item EV_STAT_ENABLE 3148=item EV_STAT_ENABLE
3147 3149
3148If undefined or defined to be C<1>, then stat watchers are supported. If 3150If undefined or defined to be C<1>, then stat watchers are supported. If
3149defined to be C<0>, then they are not. 3151defined to be C<0>, then they are not.
3181two). 3183two).
3182 3184
3183=item EV_USE_4HEAP 3185=item EV_USE_4HEAP
3184 3186
3185Heaps are not very cache-efficient. To improve the cache-efficiency of the 3187Heaps 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 3188timer 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 3189to C<1>. The 4-heap uses more complicated (longer) code but has noticeably
3188noticeably faster performance with many (thousands) of watchers. 3190faster performance with many (thousands) of watchers.
3189 3191
3190The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0> 3192The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0>
3191(disabled). 3193(disabled).
3192 3194
3193=item EV_HEAP_CACHE_AT 3195=item EV_HEAP_CACHE_AT
3194 3196
3195Heaps are not very cache-efficient. To improve the cache-efficiency of the 3197Heaps are not very cache-efficient. To improve the cache-efficiency of the
3196timer and periodics heap, libev can cache the timestamp (I<at>) within 3198timer 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>), 3199the 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, 3200which 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 3201but avoids random read accesses on heap changes. This improves performance
3200noticeably with with many (hundreds) of watchers. 3202noticeably with many (hundreds) of watchers.
3201 3203
3202The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0> 3204The default is C<1> unless C<EV_MINIMAL> is set in which case it is C<0>
3203(disabled). 3205(disabled).
3204 3206
3205=item EV_VERIFY 3207=item EV_VERIFY
3211called once per loop, which can slow down libev. If set to C<3>, then the 3213called 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 3214verification code will be called very frequently, which will slow down
3213libev considerably. 3215libev considerably.
3214 3216
3215The default is C<1>, unless C<EV_MINIMAL> is set, in which case it will be 3217The default is C<1>, unless C<EV_MINIMAL> is set, in which case it will be
3216C<0.> 3218C<0>.
3217 3219
3218=item EV_COMMON 3220=item EV_COMMON
3219 3221
3220By default, all watchers have a C<void *data> member. By redefining 3222By 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 3223this macro to a something else you can include more and other types of
3303 3305
3304Libev itself is thread-safe (unless the opposite is specifically 3306Libev itself is thread-safe (unless the opposite is specifically
3305documented for a function), but it uses no locking itself. This means that 3307documented for a function), but it uses no locking itself. This means that
3306you can use as many loops as you want in parallel, as long as only one 3308you can use as many loops as you want in parallel, as long as only one
3307thread ever calls into one libev function with the same loop parameter: 3309thread ever calls into one libev function with the same loop parameter:
3308libev guarentees that different event loops share no data structures that 3310libev guarantees that different event loops share no data structures that
3309need locking. 3311need locking.
3310 3312
3311Or to put it differently: calls with different loop parameters can be done 3313Or to put it differently: calls with different loop parameters can be done
3312concurrently from multiple threads, calls with the same loop parameter 3314concurrently from multiple threads, calls with the same loop parameter
3313must be done serially (but can be done from different threads, as long as 3315must be done serially (but can be done from different threads, as long as
3420=item Priority handling: O(number_of_priorities) 3422=item Priority handling: O(number_of_priorities)
3421 3423
3422Priorities are implemented by allocating some space for each 3424Priorities are implemented by allocating some space for each
3423priority. When doing priority-based operations, libev usually has to 3425priority. When doing priority-based operations, libev usually has to
3424linearly search all the priorities, but starting/stopping and activating 3426linearly search all the priorities, but starting/stopping and activating
3425watchers becomes O(1) w.r.t. priority handling. 3427watchers becomes O(1) with respect to priority handling.
3426 3428
3427=item Sending an ev_async: O(1) 3429=item Sending an ev_async: O(1)
3428 3430
3429=item Processing ev_async_send: O(number_of_async_watchers) 3431=item Processing ev_async_send: O(number_of_async_watchers)
3430 3432
3456 3458
3457Not a libev limitation but worth mentioning: windows apparently doesn't 3459Not a libev limitation but worth mentioning: windows apparently doesn't
3458accept large writes: instead of resulting in a partial write, windows will 3460accept large writes: instead of resulting in a partial write, windows will
3459either accept everything or return C<ENOBUFS> if the buffer is too large, 3461either 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 3462so 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 3463megabyte seems safe, but this apparently depends on the amount of memory
3462available). 3464available).
3463 3465
3464Due to the many, low, and arbitrary limits on the win32 platform and 3466Due to the many, low, and arbitrary limits on the win32 platform and
3465the abysmal performance of winsockets, using a large number of sockets 3467the abysmal performance of winsockets, using a large number of sockets
3466is not recommended (and not reasonable). If your program needs to use 3468is not recommended (and not reasonable). If your program needs to use
3477 #define EV_SELECT_IS_WINSOCKET 1 /* configure libev for windows select */ 3479 #define EV_SELECT_IS_WINSOCKET 1 /* configure libev for windows select */
3478 3480
3479 #include "ev.h" 3481 #include "ev.h"
3480 3482
3481And compile the following F<evwrap.c> file into your project (make sure 3483And 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!): 3484you do I<not> compile the F<ev.c> or any other embedded source files!):
3483 3485
3484 #include "evwrap.h" 3486 #include "evwrap.h"
3485 #include "ev.c" 3487 #include "ev.c"
3486 3488
3487=over 4 3489=over 4
3552calls them using an C<ev_watcher *> internally. 3554calls them using an C<ev_watcher *> internally.
3553 3555
3554=item C<sig_atomic_t volatile> must be thread-atomic as well 3556=item C<sig_atomic_t volatile> must be thread-atomic as well
3555 3557
3556The type C<sig_atomic_t volatile> (or whatever is defined as 3558The type C<sig_atomic_t volatile> (or whatever is defined as
3557C<EV_ATOMIC_T>) must be atomic w.r.t. accesses from different 3559C<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 3560threads. This is not part of the specification for C<sig_atomic_t>, but is
3559believed to be sufficiently portable. 3561believed to be sufficiently portable.
3560 3562
3561=item C<sigprocmask> must work in a threaded environment 3563=item C<sigprocmask> must work in a threaded environment
3562 3564

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines