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

Comparing libev/ev.pod (file contents):
Revision 1.395 by root, Tue Jan 24 16:38:55 2012 UTC vs.
Revision 1.402 by root, Wed Apr 18 06:09:29 2012 UTC

247the current system, you would need to look at C<ev_embeddable_backends () 247the current system, you would need to look at C<ev_embeddable_backends ()
248& ev_supported_backends ()>, likewise for recommended ones. 248& ev_supported_backends ()>, likewise for recommended ones.
249 249
250See the description of C<ev_embed> watchers for more info. 250See the description of C<ev_embed> watchers for more info.
251 251
252=item ev_set_allocator (void *(*cb)(void *ptr, long size)) 252=item ev_set_allocator (void *(*cb)(void *ptr, long size) throw ())
253 253
254Sets the allocation function to use (the prototype is similar - the 254Sets the allocation function to use (the prototype is similar - the
255semantics are identical to the C<realloc> C89/SuS/POSIX function). It is 255semantics are identical to the C<realloc> C89/SuS/POSIX function). It is
256used to allocate and free memory (no surprises here). If it returns zero 256used to allocate and free memory (no surprises here). If it returns zero
257when memory needs to be allocated (C<size != 0>), the library might abort 257when memory needs to be allocated (C<size != 0>), the library might abort
283 } 283 }
284 284
285 ... 285 ...
286 ev_set_allocator (persistent_realloc); 286 ev_set_allocator (persistent_realloc);
287 287
288=item ev_set_syserr_cb (void (*cb)(const char *msg)) 288=item ev_set_syserr_cb (void (*cb)(const char *msg) throw ())
289 289
290Set the callback function to call on a retryable system call error (such 290Set the callback function to call on a retryable system call error (such
291as failed select, poll, epoll_wait). The message is a printable string 291as failed select, poll, epoll_wait). The message is a printable string
292indicating the system call or subsystem causing the problem. If this 292indicating the system call or subsystem causing the problem. If this
293callback is set, then libev will expect it to remedy the situation, no 293callback is set, then libev will expect it to remedy the situation, no
567 567
568It scales in the same way as the epoll backend, but the interface to the 568It scales in the same way as the epoll backend, but the interface to the
569kernel is more efficient (which says nothing about its actual speed, of 569kernel is more efficient (which says nothing about its actual speed, of
570course). While stopping, setting and starting an I/O watcher does never 570course). While stopping, setting and starting an I/O watcher does never
571cause an extra system call as with C<EVBACKEND_EPOLL>, it still adds up to 571cause an extra system call as with C<EVBACKEND_EPOLL>, it still adds up to
572two event changes per incident. Support for C<fork ()> is very bad (but 572two event changes per incident. Support for C<fork ()> is very bad (you
573sane, unlike epoll) and it drops fds silently in similarly hard-to-detect 573might have to leak fd's on fork, but it's more sane than epoll) and it
574cases 574drops fds silently in similarly hard-to-detect cases
575 575
576This backend usually performs well under most conditions. 576This backend usually performs well under most conditions.
577 577
578While nominally embeddable in other event loops, this doesn't work 578While nominally embeddable in other event loops, this doesn't work
579everywhere, so you might need to test for this. And since it is broken 579everywhere, so you might need to test for this. And since it is broken
792without a previous call to C<ev_suspend>. 792without a previous call to C<ev_suspend>.
793 793
794Calling C<ev_suspend>/C<ev_resume> has the side effect of updating the 794Calling C<ev_suspend>/C<ev_resume> has the side effect of updating the
795event loop time (see C<ev_now_update>). 795event loop time (see C<ev_now_update>).
796 796
797=item ev_run (loop, int flags) 797=item bool ev_run (loop, int flags)
798 798
799Finally, this is it, the event handler. This function usually is called 799Finally, this is it, the event handler. This function usually is called
800after you have initialised all your watchers and you want to start 800after you have initialised all your watchers and you want to start
801handling events. It will ask the operating system for any new events, call 801handling events. It will ask the operating system for any new events, call
802the watcher callbacks, an then repeat the whole process indefinitely: This 802the watcher callbacks, and then repeat the whole process indefinitely: This
803is why event loops are called I<loops>. 803is why event loops are called I<loops>.
804 804
805If the flags argument is specified as C<0>, it will keep handling events 805If the flags argument is specified as C<0>, it will keep handling events
806until either no event watchers are active anymore or C<ev_break> was 806until either no event watchers are active anymore or C<ev_break> was
807called. 807called.
808
809The return value is false if there are no more active watchers (which
810usually means "all jobs done" or "deadlock"), and true in all other cases
811(which usually means " you should call C<ev_run> again").
808 812
809Please note that an explicit C<ev_break> is usually better than 813Please note that an explicit C<ev_break> is usually better than
810relying on all watchers to be stopped when deciding when a program has 814relying on all watchers to be stopped when deciding when a program has
811finished (especially in interactive programs), but having a program 815finished (especially in interactive programs), but having a program
812that automatically loops as long as it has to and no longer by virtue 816that automatically loops as long as it has to and no longer by virtue
813of relying on its watchers stopping correctly, that is truly a thing of 817of relying on its watchers stopping correctly, that is truly a thing of
814beauty. 818beauty.
815 819
816This function is also I<mostly> exception-safe - you can break out of 820This function is I<mostly> exception-safe - you can break out of a
817a C<ev_run> call by calling C<longjmp> in a callback, throwing a C++ 821C<ev_run> call by calling C<longjmp> in a callback, throwing a C++
818exception and so on. This does not decrement the C<ev_depth> value, nor 822exception and so on. This does not decrement the C<ev_depth> value, nor
819will it clear any outstanding C<EVBREAK_ONE> breaks. 823will it clear any outstanding C<EVBREAK_ONE> breaks.
820 824
821A flags value of C<EVRUN_NOWAIT> will look for new events, will handle 825A flags value of C<EVRUN_NOWAIT> will look for new events, will handle
822those events and any already outstanding ones, but will not wait and 826those events and any already outstanding ones, but will not wait and
1012invoke the actual watchers inside another context (another thread etc.). 1016invoke the actual watchers inside another context (another thread etc.).
1013 1017
1014If you want to reset the callback, use C<ev_invoke_pending> as new 1018If you want to reset the callback, use C<ev_invoke_pending> as new
1015callback. 1019callback.
1016 1020
1017=item ev_set_loop_release_cb (loop, void (*release)(EV_P), void (*acquire)(EV_P)) 1021=item ev_set_loop_release_cb (loop, void (*release)(EV_P) throw (), void (*acquire)(EV_P) throw ())
1018 1022
1019Sometimes you want to share the same loop between multiple threads. This 1023Sometimes you want to share the same loop between multiple threads. This
1020can be done relatively simply by putting mutex_lock/unlock calls around 1024can be done relatively simply by putting mutex_lock/unlock calls around
1021each call to a libev function. 1025each call to a libev function.
1022 1026
3893 3897
3894=back 3898=back
3895 3899
3896=head1 C++ SUPPORT 3900=head1 C++ SUPPORT
3897 3901
3902=head2 C API
3903
3904The normal C API should work fine when used from C++: both ev.h and the
3905libev sources can be compiled as C++. Therefore, code that uses the C API
3906will work fine.
3907
3908Proper exception specifications might have to be added to callbacks passed
3909to libev: exceptions may be thrown only from watcher callbacks, all
3910other callbacks (allocator, syserr, loop acquire/release and periodioc
3911reschedule callbacks) must not throw exceptions, and might need a C<throw
3912()> specification. If you have code that needs to be compiled as both C
3913and C++ you can use the C<EV_THROW> macro for this:
3914
3915 static void
3916 fatal_error (const char *msg) EV_THROW
3917 {
3918 perror (msg);
3919 abort ();
3920 }
3921
3922 ...
3923 ev_set_syserr_cb (fatal_error);
3924
3925The only API functions that can currently throw exceptions are C<ev_run>,
3926C<ev_inoke>, C<ev_invoke_pending> and C<ev_loop_destroy> (the latter
3927because it runs cleanup watchers).
3928
3929Throwing exceptions in watcher callbacks is only supported if libev itself
3930is compiled with a C++ compiler or your C and C++ environments allow
3931throwing exceptions through C libraries (most do).
3932
3933=head2 C++ API
3934
3898Libev comes with some simplistic wrapper classes for C++ that mainly allow 3935Libev comes with some simplistic wrapper classes for C++ that mainly allow
3899you to use some convenience methods to start/stop watchers and also change 3936you to use some convenience methods to start/stop watchers and also change
3900the callback model to a model using method callbacks on objects. 3937the callback model to a model using method callbacks on objects.
3901 3938
3902To use it, 3939To use it,
3916Currently, functions, static and non-static member functions and classes 3953Currently, functions, static and non-static member functions and classes
3917with C<operator ()> can be used as callbacks. Other types should be easy 3954with C<operator ()> can be used as callbacks. Other types should be easy
3918to add as long as they only need one additional pointer for context. If 3955to add as long as they only need one additional pointer for context. If
3919you need support for other types of functors please contact the author 3956you need support for other types of functors please contact the author
3920(preferably after implementing it). 3957(preferably after implementing it).
3958
3959For all this to work, your C++ compiler either has to use the same calling
3960conventions as your C compiler (for static member functions), or you have
3961to embed libev and compile libev itself as C++.
3921 3962
3922Here is a list of things available in the C<ev> namespace: 3963Here is a list of things available in the C<ev> namespace:
3923 3964
3924=over 4 3965=over 4
3925 3966
4504If defined to be C<1>, libev will compile in support for the Linux inotify 4545If defined to be C<1>, libev will compile in support for the Linux inotify
4505interface to speed up C<ev_stat> watchers. Its actual availability will 4546interface to speed up C<ev_stat> watchers. Its actual availability will
4506be detected at runtime. If undefined, it will be enabled if the headers 4547be detected at runtime. If undefined, it will be enabled if the headers
4507indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. 4548indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
4508 4549
4550=item EV_NO_SMP
4551
4552If defined to be C<1>, libev will assume that memory is always coherent
4553between threads, that is, threads can be used, but threads never run on
4554different cpus (or different cpu cores). This reduces dependencies
4555and makes libev faster.
4556
4557=item EV_NO_THREADS
4558
4559If defined to be C<1>, libev will assume that it will never be called
4560from different threads, which is a stronger assumption than C<EV_NO_SMP>,
4561above. This reduces dependencies and makes libev faster.
4562
4509=item EV_ATOMIC_T 4563=item EV_ATOMIC_T
4510 4564
4511Libev requires an integer type (suitable for storing C<0> or C<1>) whose 4565Libev requires an integer type (suitable for storing C<0> or C<1>) whose
4512access is atomic and serialised with respect to other threads or signal 4566access is atomic and serialised with respect to other threads or signal
4513contexts. No such type is easily found in the C language, so you can 4567contexts. No such type is easily found in the C language, so you can
4599 #define EV_USE_POLL 1 4653 #define EV_USE_POLL 1
4600 #define EV_CHILD_ENABLE 1 4654 #define EV_CHILD_ENABLE 1
4601 #define EV_ASYNC_ENABLE 1 4655 #define EV_ASYNC_ENABLE 1
4602 4656
4603The actual value is a bitset, it can be a combination of the following 4657The actual value is a bitset, it can be a combination of the following
4604values: 4658values (by default, all of these are enabled):
4605 4659
4606=over 4 4660=over 4
4607 4661
4608=item C<1> - faster/larger code 4662=item C<1> - faster/larger code
4609 4663
4613code size by roughly 30% on amd64). 4667code size by roughly 30% on amd64).
4614 4668
4615When optimising for size, use of compiler flags such as C<-Os> with 4669When optimising for size, use of compiler flags such as C<-Os> with
4616gcc is recommended, as well as C<-DNDEBUG>, as libev contains a number of 4670gcc is recommended, as well as C<-DNDEBUG>, as libev contains a number of
4617assertions. 4671assertions.
4672
4673The default is off when C<__OPTIMIZE_SIZE__> is defined by your compiler
4674(e.g. gcc with C<-Os>).
4618 4675
4619=item C<2> - faster/larger data structures 4676=item C<2> - faster/larger data structures
4620 4677
4621Replaces the small 2-heap for timer management by a faster 4-heap, larger 4678Replaces the small 2-heap for timer management by a faster 4-heap, larger
4622hash table sizes and so on. This will usually further increase code size 4679hash table sizes and so on. This will usually further increase code size
4623and can additionally have an effect on the size of data structures at 4680and can additionally have an effect on the size of data structures at
4624runtime. 4681runtime.
4682
4683The default is off when C<__OPTIMIZE_SIZE__> is defined by your compiler
4684(e.g. gcc with C<-Os>).
4625 4685
4626=item C<4> - full API configuration 4686=item C<4> - full API configuration
4627 4687
4628This enables priorities (sets C<EV_MAXPRI>=2 and C<EV_MINPRI>=-2), and 4688This enables priorities (sets C<EV_MAXPRI>=2 and C<EV_MINPRI>=-2), and
4629enables multiplicity (C<EV_MULTIPLICITY>=1). 4689enables multiplicity (C<EV_MULTIPLICITY>=1).

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines