… | |
… | |
122 | .\} |
122 | .\} |
123 | .rm #[ #] #H #V #F C |
123 | .rm #[ #] #H #V #F C |
124 | .\" ======================================================================== |
124 | .\" ======================================================================== |
125 | .\" |
125 | .\" |
126 | .IX Title "LIBEV 3" |
126 | .IX Title "LIBEV 3" |
127 | .TH LIBEV 3 "2012-03-23" "libev-4.11" "libev - high performance full featured event loop" |
127 | .TH LIBEV 3 "2012-04-19" "libev-4.11" "libev - high performance full featured event loop" |
128 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
128 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
129 | .\" way too many mistakes in technical documents. |
129 | .\" way too many mistakes in technical documents. |
130 | .if n .ad l |
130 | .if n .ad l |
131 | .nh |
131 | .nh |
132 | .SH "NAME" |
132 | .SH "NAME" |
… | |
… | |
367 | current system. To find which embeddable backends might be supported on |
367 | current system. To find which embeddable backends might be supported on |
368 | the current system, you would need to look at \f(CW\*(C`ev_embeddable_backends () |
368 | the current system, you would need to look at \f(CW\*(C`ev_embeddable_backends () |
369 | & ev_supported_backends ()\*(C'\fR, likewise for recommended ones. |
369 | & ev_supported_backends ()\*(C'\fR, likewise for recommended ones. |
370 | .Sp |
370 | .Sp |
371 | See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
371 | See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
372 | .IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4 |
372 | .IP "ev_set_allocator (void *(*cb)(void *ptr, long size) throw ())" 4 |
373 | .IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))" |
373 | .IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size) throw ())" |
374 | Sets the allocation function to use (the prototype is similar \- the |
374 | Sets the allocation function to use (the prototype is similar \- the |
375 | semantics are identical to the \f(CW\*(C`realloc\*(C'\fR C89/SuS/POSIX function). It is |
375 | semantics are identical to the \f(CW\*(C`realloc\*(C'\fR C89/SuS/POSIX function). It is |
376 | used to allocate and free memory (no surprises here). If it returns zero |
376 | used to allocate and free memory (no surprises here). If it returns zero |
377 | when memory needs to be allocated (\f(CW\*(C`size != 0\*(C'\fR), the library might abort |
377 | when memory needs to be allocated (\f(CW\*(C`size != 0\*(C'\fR), the library might abort |
378 | or take some potentially destructive action. |
378 | or take some potentially destructive action. |
… | |
… | |
404 | \& } |
404 | \& } |
405 | \& |
405 | \& |
406 | \& ... |
406 | \& ... |
407 | \& ev_set_allocator (persistent_realloc); |
407 | \& ev_set_allocator (persistent_realloc); |
408 | .Ve |
408 | .Ve |
409 | .IP "ev_set_syserr_cb (void (*cb)(const char *msg))" 4 |
409 | .IP "ev_set_syserr_cb (void (*cb)(const char *msg) throw ())" 4 |
410 | .IX Item "ev_set_syserr_cb (void (*cb)(const char *msg))" |
410 | .IX Item "ev_set_syserr_cb (void (*cb)(const char *msg) throw ())" |
411 | Set the callback function to call on a retryable system call error (such |
411 | Set the callback function to call on a retryable system call error (such |
412 | as failed select, poll, epoll_wait). The message is a printable string |
412 | as failed select, poll, epoll_wait). The message is a printable string |
413 | indicating the system call or subsystem causing the problem. If this |
413 | indicating the system call or subsystem causing the problem. If this |
414 | callback is set, then libev will expect it to remedy the situation, no |
414 | callback is set, then libev will expect it to remedy the situation, no |
415 | matter what, when it returns. That is, libev will generally retry the |
415 | matter what, when it returns. That is, libev will generally retry the |
… | |
… | |
685 | .Sp |
685 | .Sp |
686 | It scales in the same way as the epoll backend, but the interface to the |
686 | It scales in the same way as the epoll backend, but the interface to the |
687 | kernel is more efficient (which says nothing about its actual speed, of |
687 | kernel is more efficient (which says nothing about its actual speed, of |
688 | course). While stopping, setting and starting an I/O watcher does never |
688 | course). While stopping, setting and starting an I/O watcher does never |
689 | cause an extra system call as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to |
689 | cause an extra system call as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to |
690 | two event changes per incident. Support for \f(CW\*(C`fork ()\*(C'\fR is very bad (but |
690 | two event changes per incident. Support for \f(CW\*(C`fork ()\*(C'\fR is very bad (you |
691 | sane, unlike epoll) and it drops fds silently in similarly hard-to-detect |
691 | might have to leak fd's on fork, but it's more sane than epoll) and it |
692 | cases |
692 | drops fds silently in similarly hard-to-detect cases |
693 | .Sp |
693 | .Sp |
694 | This backend usually performs well under most conditions. |
694 | This backend usually performs well under most conditions. |
695 | .Sp |
695 | .Sp |
696 | While nominally embeddable in other event loops, this doesn't work |
696 | While nominally embeddable in other event loops, this doesn't work |
697 | everywhere, so you might need to test for this. And since it is broken |
697 | everywhere, so you might need to test for this. And since it is broken |
… | |
… | |
909 | given loop other than \f(CW\*(C`ev_resume\*(C'\fR, and you \fBmust not\fR call \f(CW\*(C`ev_resume\*(C'\fR |
909 | given loop other than \f(CW\*(C`ev_resume\*(C'\fR, and you \fBmust not\fR call \f(CW\*(C`ev_resume\*(C'\fR |
910 | without a previous call to \f(CW\*(C`ev_suspend\*(C'\fR. |
910 | without a previous call to \f(CW\*(C`ev_suspend\*(C'\fR. |
911 | .Sp |
911 | .Sp |
912 | Calling \f(CW\*(C`ev_suspend\*(C'\fR/\f(CW\*(C`ev_resume\*(C'\fR has the side effect of updating the |
912 | Calling \f(CW\*(C`ev_suspend\*(C'\fR/\f(CW\*(C`ev_resume\*(C'\fR has the side effect of updating the |
913 | event loop time (see \f(CW\*(C`ev_now_update\*(C'\fR). |
913 | event loop time (see \f(CW\*(C`ev_now_update\*(C'\fR). |
914 | .IP "ev_run (loop, int flags)" 4 |
914 | .IP "bool ev_run (loop, int flags)" 4 |
915 | .IX Item "ev_run (loop, int flags)" |
915 | .IX Item "bool ev_run (loop, int flags)" |
916 | Finally, this is it, the event handler. This function usually is called |
916 | Finally, this is it, the event handler. This function usually is called |
917 | after you have initialised all your watchers and you want to start |
917 | after you have initialised all your watchers and you want to start |
918 | handling events. It will ask the operating system for any new events, call |
918 | handling events. It will ask the operating system for any new events, call |
919 | the watcher callbacks, an then repeat the whole process indefinitely: This |
919 | the watcher callbacks, and then repeat the whole process indefinitely: This |
920 | is why event loops are called \fIloops\fR. |
920 | is why event loops are called \fIloops\fR. |
921 | .Sp |
921 | .Sp |
922 | If the flags argument is specified as \f(CW0\fR, it will keep handling events |
922 | If the flags argument is specified as \f(CW0\fR, it will keep handling events |
923 | until either no event watchers are active anymore or \f(CW\*(C`ev_break\*(C'\fR was |
923 | until either no event watchers are active anymore or \f(CW\*(C`ev_break\*(C'\fR was |
924 | called. |
924 | called. |
|
|
925 | .Sp |
|
|
926 | The return value is false if there are no more active watchers (which |
|
|
927 | usually means \*(L"all jobs done\*(R" or \*(L"deadlock\*(R"), and true in all other cases |
|
|
928 | (which usually means " you should call \f(CW\*(C`ev_run\*(C'\fR again"). |
925 | .Sp |
929 | .Sp |
926 | Please note that an explicit \f(CW\*(C`ev_break\*(C'\fR is usually better than |
930 | Please note that an explicit \f(CW\*(C`ev_break\*(C'\fR is usually better than |
927 | relying on all watchers to be stopped when deciding when a program has |
931 | relying on all watchers to be stopped when deciding when a program has |
928 | finished (especially in interactive programs), but having a program |
932 | finished (especially in interactive programs), but having a program |
929 | that automatically loops as long as it has to and no longer by virtue |
933 | that automatically loops as long as it has to and no longer by virtue |
930 | of relying on its watchers stopping correctly, that is truly a thing of |
934 | of relying on its watchers stopping correctly, that is truly a thing of |
931 | beauty. |
935 | beauty. |
932 | .Sp |
936 | .Sp |
933 | This function is also \fImostly\fR exception-safe \- you can break out of |
937 | This function is \fImostly\fR exception-safe \- you can break out of a |
934 | a \f(CW\*(C`ev_run\*(C'\fR call by calling \f(CW\*(C`longjmp\*(C'\fR in a callback, throwing a \*(C+ |
938 | \&\f(CW\*(C`ev_run\*(C'\fR call by calling \f(CW\*(C`longjmp\*(C'\fR in a callback, throwing a \*(C+ |
935 | exception and so on. This does not decrement the \f(CW\*(C`ev_depth\*(C'\fR value, nor |
939 | exception and so on. This does not decrement the \f(CW\*(C`ev_depth\*(C'\fR value, nor |
936 | will it clear any outstanding \f(CW\*(C`EVBREAK_ONE\*(C'\fR breaks. |
940 | will it clear any outstanding \f(CW\*(C`EVBREAK_ONE\*(C'\fR breaks. |
937 | .Sp |
941 | .Sp |
938 | A flags value of \f(CW\*(C`EVRUN_NOWAIT\*(C'\fR will look for new events, will handle |
942 | A flags value of \f(CW\*(C`EVRUN_NOWAIT\*(C'\fR will look for new events, will handle |
939 | those events and any already outstanding ones, but will not wait and |
943 | those events and any already outstanding ones, but will not wait and |
… | |
… | |
1136 | this callback instead. This is useful, for example, when you want to |
1140 | this callback instead. This is useful, for example, when you want to |
1137 | invoke the actual watchers inside another context (another thread etc.). |
1141 | invoke the actual watchers inside another context (another thread etc.). |
1138 | .Sp |
1142 | .Sp |
1139 | If you want to reset the callback, use \f(CW\*(C`ev_invoke_pending\*(C'\fR as new |
1143 | If you want to reset the callback, use \f(CW\*(C`ev_invoke_pending\*(C'\fR as new |
1140 | callback. |
1144 | callback. |
1141 | .IP "ev_set_loop_release_cb (loop, void (*release)(\s-1EV_P\s0), void (*acquire)(\s-1EV_P\s0))" 4 |
1145 | .IP "ev_set_loop_release_cb (loop, void (*release)(\s-1EV_P\s0) throw (), void (*acquire)(\s-1EV_P\s0) throw ())" 4 |
1142 | .IX Item "ev_set_loop_release_cb (loop, void (*release)(EV_P), void (*acquire)(EV_P))" |
1146 | .IX Item "ev_set_loop_release_cb (loop, void (*release)(EV_P) throw (), void (*acquire)(EV_P) throw ())" |
1143 | Sometimes you want to share the same loop between multiple threads. This |
1147 | Sometimes you want to share the same loop between multiple threads. This |
1144 | can be done relatively simply by putting mutex_lock/unlock calls around |
1148 | can be done relatively simply by putting mutex_lock/unlock calls around |
1145 | each call to a libev function. |
1149 | each call to a libev function. |
1146 | .Sp |
1150 | .Sp |
1147 | However, \f(CW\*(C`ev_run\*(C'\fR can run an indefinite time, so it is not feasible |
1151 | However, \f(CW\*(C`ev_run\*(C'\fR can run an indefinite time, so it is not feasible |
… | |
… | |
4030 | .IP "\(bu" 4 |
4034 | .IP "\(bu" 4 |
4031 | The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need |
4035 | The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need |
4032 | to use the libev header file and library. |
4036 | to use the libev header file and library. |
4033 | .SH "\*(C+ SUPPORT" |
4037 | .SH "\*(C+ SUPPORT" |
4034 | .IX Header " SUPPORT" |
4038 | .IX Header " SUPPORT" |
|
|
4039 | .SS "C \s-1API\s0" |
|
|
4040 | .IX Subsection "C API" |
|
|
4041 | The normal C \s-1API\s0 should work fine when used from \*(C+: both ev.h and the |
|
|
4042 | libev sources can be compiled as \*(C+. Therefore, code that uses the C \s-1API\s0 |
|
|
4043 | will work fine. |
|
|
4044 | .PP |
|
|
4045 | Proper exception specifications might have to be added to callbacks passed |
|
|
4046 | to libev: exceptions may be thrown only from watcher callbacks, all |
|
|
4047 | other callbacks (allocator, syserr, loop acquire/release and periodioc |
|
|
4048 | reschedule callbacks) must not throw exceptions, and might need a \f(CW\*(C`throw |
|
|
4049 | ()\*(C'\fR specification. If you have code that needs to be compiled as both C |
|
|
4050 | and \*(C+ you can use the \f(CW\*(C`EV_THROW\*(C'\fR macro for this: |
|
|
4051 | .PP |
|
|
4052 | .Vb 6 |
|
|
4053 | \& static void |
|
|
4054 | \& fatal_error (const char *msg) EV_THROW |
|
|
4055 | \& { |
|
|
4056 | \& perror (msg); |
|
|
4057 | \& abort (); |
|
|
4058 | \& } |
|
|
4059 | \& |
|
|
4060 | \& ... |
|
|
4061 | \& ev_set_syserr_cb (fatal_error); |
|
|
4062 | .Ve |
|
|
4063 | .PP |
|
|
4064 | The only \s-1API\s0 functions that can currently throw exceptions are \f(CW\*(C`ev_run\*(C'\fR, |
|
|
4065 | \&\f(CW\*(C`ev_inoke\*(C'\fR, \f(CW\*(C`ev_invoke_pending\*(C'\fR and \f(CW\*(C`ev_loop_destroy\*(C'\fR (the latter |
|
|
4066 | because it runs cleanup watchers). |
|
|
4067 | .PP |
|
|
4068 | Throwing exceptions in watcher callbacks is only supported if libev itself |
|
|
4069 | is compiled with a \*(C+ compiler or your C and \*(C+ environments allow |
|
|
4070 | throwing exceptions through C libraries (most do). |
|
|
4071 | .SS "\*(C+ \s-1API\s0" |
|
|
4072 | .IX Subsection " API" |
4035 | Libev comes with some simplistic wrapper classes for \*(C+ that mainly allow |
4073 | Libev comes with some simplistic wrapper classes for \*(C+ that mainly allow |
4036 | you to use some convenience methods to start/stop watchers and also change |
4074 | you to use some convenience methods to start/stop watchers and also change |
4037 | the callback model to a model using method callbacks on objects. |
4075 | the callback model to a model using method callbacks on objects. |
4038 | .PP |
4076 | .PP |
4039 | To use it, |
4077 | To use it, |
… | |
… | |
4722 | \& #define EV_CHILD_ENABLE 1 |
4760 | \& #define EV_CHILD_ENABLE 1 |
4723 | \& #define EV_ASYNC_ENABLE 1 |
4761 | \& #define EV_ASYNC_ENABLE 1 |
4724 | .Ve |
4762 | .Ve |
4725 | .Sp |
4763 | .Sp |
4726 | The actual value is a bitset, it can be a combination of the following |
4764 | The actual value is a bitset, it can be a combination of the following |
4727 | values: |
4765 | values (by default, all of these are enabled): |
4728 | .RS 4 |
4766 | .RS 4 |
4729 | .ie n .IP "1 \- faster/larger code" 4 |
4767 | .ie n .IP "1 \- faster/larger code" 4 |
4730 | .el .IP "\f(CW1\fR \- faster/larger code" 4 |
4768 | .el .IP "\f(CW1\fR \- faster/larger code" 4 |
4731 | .IX Item "1 - faster/larger code" |
4769 | .IX Item "1 - faster/larger code" |
4732 | Use larger code to speed up some operations. |
4770 | Use larger code to speed up some operations. |
… | |
… | |
4735 | code size by roughly 30% on amd64). |
4773 | code size by roughly 30% on amd64). |
4736 | .Sp |
4774 | .Sp |
4737 | When optimising for size, use of compiler flags such as \f(CW\*(C`\-Os\*(C'\fR with |
4775 | When optimising for size, use of compiler flags such as \f(CW\*(C`\-Os\*(C'\fR with |
4738 | gcc is recommended, as well as \f(CW\*(C`\-DNDEBUG\*(C'\fR, as libev contains a number of |
4776 | gcc is recommended, as well as \f(CW\*(C`\-DNDEBUG\*(C'\fR, as libev contains a number of |
4739 | assertions. |
4777 | assertions. |
|
|
4778 | .Sp |
|
|
4779 | The default is off when \f(CW\*(C`_\|_OPTIMIZE_SIZE_\|_\*(C'\fR is defined by your compiler |
|
|
4780 | (e.g. gcc with \f(CW\*(C`\-Os\*(C'\fR). |
4740 | .ie n .IP "2 \- faster/larger data structures" 4 |
4781 | .ie n .IP "2 \- faster/larger data structures" 4 |
4741 | .el .IP "\f(CW2\fR \- faster/larger data structures" 4 |
4782 | .el .IP "\f(CW2\fR \- faster/larger data structures" 4 |
4742 | .IX Item "2 - faster/larger data structures" |
4783 | .IX Item "2 - faster/larger data structures" |
4743 | Replaces the small 2\-heap for timer management by a faster 4\-heap, larger |
4784 | Replaces the small 2\-heap for timer management by a faster 4\-heap, larger |
4744 | hash table sizes and so on. This will usually further increase code size |
4785 | hash table sizes and so on. This will usually further increase code size |
4745 | and can additionally have an effect on the size of data structures at |
4786 | and can additionally have an effect on the size of data structures at |
4746 | runtime. |
4787 | runtime. |
|
|
4788 | .Sp |
|
|
4789 | The default is off when \f(CW\*(C`_\|_OPTIMIZE_SIZE_\|_\*(C'\fR is defined by your compiler |
|
|
4790 | (e.g. gcc with \f(CW\*(C`\-Os\*(C'\fR). |
4747 | .ie n .IP "4 \- full \s-1API\s0 configuration" 4 |
4791 | .ie n .IP "4 \- full \s-1API\s0 configuration" 4 |
4748 | .el .IP "\f(CW4\fR \- full \s-1API\s0 configuration" 4 |
4792 | .el .IP "\f(CW4\fR \- full \s-1API\s0 configuration" 4 |
4749 | .IX Item "4 - full API configuration" |
4793 | .IX Item "4 - full API configuration" |
4750 | This enables priorities (sets \f(CW\*(C`EV_MAXPRI\*(C'\fR=2 and \f(CW\*(C`EV_MINPRI\*(C'\fR=\-2), and |
4794 | This enables priorities (sets \f(CW\*(C`EV_MAXPRI\*(C'\fR=2 and \f(CW\*(C`EV_MINPRI\*(C'\fR=\-2), and |
4751 | enables multiplicity (\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR=1). |
4795 | enables multiplicity (\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR=1). |