1 | .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) |
1 | .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) |
2 | .\" |
2 | .\" |
3 | .\" Standard preamble: |
3 | .\" Standard preamble: |
4 | .\" ======================================================================== |
4 | .\" ======================================================================== |
5 | .de Sp \" Vertical space (when we can't use .PP) |
5 | .de Sp \" Vertical space (when we can't use .PP) |
6 | .if t .sp .5v |
6 | .if t .sp .5v |
… | |
… | |
131 | .\} |
131 | .\} |
132 | .rm #[ #] #H #V #F C |
132 | .rm #[ #] #H #V #F C |
133 | .\" ======================================================================== |
133 | .\" ======================================================================== |
134 | .\" |
134 | .\" |
135 | .IX Title "LIBEV 3" |
135 | .IX Title "LIBEV 3" |
136 | .TH LIBEV 3 "2013-10-29" "libev-4.15" "libev - high performance full featured event loop" |
136 | .TH LIBEV 3 "2014-09-05" "libev-4.15" "libev - high performance full featured event loop" |
137 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
137 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
138 | .\" way too many mistakes in technical documents. |
138 | .\" way too many mistakes in technical documents. |
139 | .if n .ad l |
139 | .if n .ad l |
140 | .nh |
140 | .nh |
141 | .SH "NAME" |
141 | .SH "NAME" |
… | |
… | |
810 | except in the rare occasion where you really need to free its resources. |
810 | except in the rare occasion where you really need to free its resources. |
811 | If you need dynamically allocated loops it is better to use \f(CW\*(C`ev_loop_new\*(C'\fR |
811 | If you need dynamically allocated loops it is better to use \f(CW\*(C`ev_loop_new\*(C'\fR |
812 | and \f(CW\*(C`ev_loop_destroy\*(C'\fR. |
812 | and \f(CW\*(C`ev_loop_destroy\*(C'\fR. |
813 | .IP "ev_loop_fork (loop)" 4 |
813 | .IP "ev_loop_fork (loop)" 4 |
814 | .IX Item "ev_loop_fork (loop)" |
814 | .IX Item "ev_loop_fork (loop)" |
815 | This function sets a flag that causes subsequent \f(CW\*(C`ev_run\*(C'\fR iterations to |
815 | This function sets a flag that causes subsequent \f(CW\*(C`ev_run\*(C'\fR iterations |
816 | reinitialise the kernel state for backends that have one. Despite the |
816 | to reinitialise the kernel state for backends that have one. Despite |
817 | name, you can call it anytime, but it makes most sense after forking, in |
817 | the name, you can call it anytime you are allowed to start or stop |
818 | the child process. You \fImust\fR call it (or use \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR) in the |
818 | watchers (except inside an \f(CW\*(C`ev_prepare\*(C'\fR callback), but it makes most |
819 | child before resuming or calling \f(CW\*(C`ev_run\*(C'\fR. |
819 | sense after forking, in the child process. You \fImust\fR call it (or use |
|
|
820 | \&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR) in the child before resuming or calling \f(CW\*(C`ev_run\*(C'\fR. |
820 | .Sp |
821 | .Sp |
821 | Again, you \fIhave\fR to call it on \fIany\fR loop that you want to re-use after |
822 | Again, you \fIhave\fR to call it on \fIany\fR loop that you want to re-use after |
822 | a fork, \fIeven if you do not plan to use the loop in the parent\fR. This is |
823 | a fork, \fIeven if you do not plan to use the loop in the parent\fR. This is |
823 | because some kernel interfaces *cough* \fIkqueue\fR *cough* do funny things |
824 | because some kernel interfaces *cough* \fIkqueue\fR *cough* do funny things |
824 | during fork. |
825 | during fork. |
… | |
… | |
2161 | .PP |
2162 | .PP |
2162 | The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR |
2163 | The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR |
2163 | time. This is usually the right thing as this timestamp refers to the time |
2164 | time. This is usually the right thing as this timestamp refers to the time |
2164 | of the event triggering whatever timeout you are modifying/starting. If |
2165 | of the event triggering whatever timeout you are modifying/starting. If |
2165 | you suspect event processing to be delayed and you \fIneed\fR to base the |
2166 | you suspect event processing to be delayed and you \fIneed\fR to base the |
2166 | timeout on the current time, use something like this to adjust for this: |
2167 | timeout on the current time, use something like the following to adjust |
|
|
2168 | for it: |
2167 | .PP |
2169 | .PP |
2168 | .Vb 1 |
2170 | .Vb 1 |
2169 | \& ev_timer_set (&timer, after + ev_now () \- ev_time (), 0.); |
2171 | \& ev_timer_set (&timer, after + (ev_time () \- ev_now ()), 0.); |
2170 | .Ve |
2172 | .Ve |
2171 | .PP |
2173 | .PP |
2172 | If the event loop is suspended for a long time, you can also force an |
2174 | If the event loop is suspended for a long time, you can also force an |
2173 | update of the time returned by \f(CW\*(C`ev_now ()\*(C'\fR by calling \f(CW\*(C`ev_now_update |
2175 | update of the time returned by \f(CW\*(C`ev_now ()\*(C'\fR by calling \f(CW\*(C`ev_now_update |
2174 | ()\*(C'\fR. |
2176 | ()\*(C'\fR, although that will push the event time of all outstanding events |
|
|
2177 | further into the future. |
2175 | .PP |
2178 | .PP |
2176 | \fIThe special problem of unsynchronised clocks\fR |
2179 | \fIThe special problem of unsynchronised clocks\fR |
2177 | .IX Subsection "The special problem of unsynchronised clocks" |
2180 | .IX Subsection "The special problem of unsynchronised clocks" |
2178 | .PP |
2181 | .PP |
2179 | Modern systems have a variety of clocks \- libev itself uses the normal |
2182 | Modern systems have a variety of clocks \- libev itself uses the normal |
… | |
… | |
2553 | only within the same loop, i.e. you can watch for \f(CW\*(C`SIGINT\*(C'\fR in your |
2556 | only within the same loop, i.e. you can watch for \f(CW\*(C`SIGINT\*(C'\fR in your |
2554 | default loop and for \f(CW\*(C`SIGIO\*(C'\fR in another loop, but you cannot watch for |
2557 | default loop and for \f(CW\*(C`SIGIO\*(C'\fR in another loop, but you cannot watch for |
2555 | \&\f(CW\*(C`SIGINT\*(C'\fR in both the default loop and another loop at the same time. At |
2558 | \&\f(CW\*(C`SIGINT\*(C'\fR in both the default loop and another loop at the same time. At |
2556 | the moment, \f(CW\*(C`SIGCHLD\*(C'\fR is permanently tied to the default loop. |
2559 | the moment, \f(CW\*(C`SIGCHLD\*(C'\fR is permanently tied to the default loop. |
2557 | .PP |
2560 | .PP |
2558 | When the first watcher gets started will libev actually register something |
2561 | Only after the first watcher for a signal is started will libev actually |
2559 | with the kernel (thus it coexists with your own signal handlers as long as |
2562 | register something with the kernel. It thus coexists with your own signal |
2560 | you don't register any with libev for the same signal). |
2563 | handlers as long as you don't register any with libev for the same signal. |
2561 | .PP |
2564 | .PP |
2562 | If possible and supported, libev will install its handlers with |
2565 | If possible and supported, libev will install its handlers with |
2563 | \&\f(CW\*(C`SA_RESTART\*(C'\fR (or equivalent) behaviour enabled, so system calls should |
2566 | \&\f(CW\*(C`SA_RESTART\*(C'\fR (or equivalent) behaviour enabled, so system calls should |
2564 | not be unduly interrupted. If you have a problem with system calls getting |
2567 | not be unduly interrupted. If you have a problem with system calls getting |
2565 | interrupted by signals you can block all signals in an \f(CW\*(C`ev_check\*(C'\fR watcher |
2568 | interrupted by signals you can block all signals in an \f(CW\*(C`ev_check\*(C'\fR watcher |
… | |
… | |
3048 | .IX Subsection "ev_prepare and ev_check - customise your event loop!" |
3051 | .IX Subsection "ev_prepare and ev_check - customise your event loop!" |
3049 | Prepare and check watchers are often (but not always) used in pairs: |
3052 | Prepare and check watchers are often (but not always) used in pairs: |
3050 | prepare watchers get invoked before the process blocks and check watchers |
3053 | prepare watchers get invoked before the process blocks and check watchers |
3051 | afterwards. |
3054 | afterwards. |
3052 | .PP |
3055 | .PP |
3053 | You \fImust not\fR call \f(CW\*(C`ev_run\*(C'\fR or similar functions that enter |
3056 | You \fImust not\fR call \f(CW\*(C`ev_run\*(C'\fR (or similar functions that enter the |
3054 | the current event loop from either \f(CW\*(C`ev_prepare\*(C'\fR or \f(CW\*(C`ev_check\*(C'\fR |
3057 | current event loop) or \f(CW\*(C`ev_loop_fork\*(C'\fR from either \f(CW\*(C`ev_prepare\*(C'\fR or |
3055 | watchers. Other loops than the current one are fine, however. The |
3058 | \&\f(CW\*(C`ev_check\*(C'\fR watchers. Other loops than the current one are fine, |
3056 | rationale behind this is that you do not need to check for recursion in |
3059 | however. The rationale behind this is that you do not need to check |
3057 | those watchers, i.e. the sequence will always be \f(CW\*(C`ev_prepare\*(C'\fR, blocking, |
3060 | for recursion in those watchers, i.e. the sequence will always be |
3058 | \&\f(CW\*(C`ev_check\*(C'\fR so if you have one watcher of each kind they will always be |
3061 | \&\f(CW\*(C`ev_prepare\*(C'\fR, blocking, \f(CW\*(C`ev_check\*(C'\fR so if you have one watcher of each |
3059 | called in pairs bracketing the blocking call. |
3062 | kind they will always be called in pairs bracketing the blocking call. |
3060 | .PP |
3063 | .PP |
3061 | Their main purpose is to integrate other event mechanisms into libev and |
3064 | Their main purpose is to integrate other event mechanisms into libev and |
3062 | their use is somewhat advanced. They could be used, for example, to track |
3065 | their use is somewhat advanced. They could be used, for example, to track |
3063 | variable changes, implement your own watchers, integrate net-snmp or a |
3066 | variable changes, implement your own watchers, integrate net-snmp or a |
3064 | coroutine library and lots more. They are also occasionally useful if |
3067 | coroutine library and lots more. They are also occasionally useful if |
… | |
… | |
3358 | .PP |
3361 | .PP |
3359 | .Vb 3 |
3362 | .Vb 3 |
3360 | \& struct ev_loop *loop_hi = ev_default_init (0); |
3363 | \& struct ev_loop *loop_hi = ev_default_init (0); |
3361 | \& struct ev_loop *loop_lo = 0; |
3364 | \& struct ev_loop *loop_lo = 0; |
3362 | \& ev_embed embed; |
3365 | \& ev_embed embed; |
3363 | \& |
3366 | \& |
3364 | \& // see if there is a chance of getting one that works |
3367 | \& // see if there is a chance of getting one that works |
3365 | \& // (remember that a flags value of 0 means autodetection) |
3368 | \& // (remember that a flags value of 0 means autodetection) |
3366 | \& loop_lo = ev_embeddable_backends () & ev_recommended_backends () |
3369 | \& loop_lo = ev_embeddable_backends () & ev_recommended_backends () |
3367 | \& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ()) |
3370 | \& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ()) |
3368 | \& : 0; |
3371 | \& : 0; |
… | |
… | |
3384 | .PP |
3387 | .PP |
3385 | .Vb 3 |
3388 | .Vb 3 |
3386 | \& struct ev_loop *loop = ev_default_init (0); |
3389 | \& struct ev_loop *loop = ev_default_init (0); |
3387 | \& struct ev_loop *loop_socket = 0; |
3390 | \& struct ev_loop *loop_socket = 0; |
3388 | \& ev_embed embed; |
3391 | \& ev_embed embed; |
3389 | \& |
3392 | \& |
3390 | \& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) |
3393 | \& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) |
3391 | \& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) |
3394 | \& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) |
3392 | \& { |
3395 | \& { |
3393 | \& ev_embed_init (&embed, 0, loop_socket); |
3396 | \& ev_embed_init (&embed, 0, loop_socket); |
3394 | \& ev_embed_start (loop, &embed); |
3397 | \& ev_embed_start (loop, &embed); |
… | |
… | |
3411 | of course. |
3414 | of course. |
3412 | .PP |
3415 | .PP |
3413 | \fIThe special problem of life after fork \- how is it possible?\fR |
3416 | \fIThe special problem of life after fork \- how is it possible?\fR |
3414 | .IX Subsection "The special problem of life after fork - how is it possible?" |
3417 | .IX Subsection "The special problem of life after fork - how is it possible?" |
3415 | .PP |
3418 | .PP |
3416 | Most uses of \f(CW\*(C`fork()\*(C'\fR consist of forking, then some simple calls to set |
3419 | Most uses of \f(CW\*(C`fork ()\*(C'\fR consist of forking, then some simple calls to set |
3417 | up/change the process environment, followed by a call to \f(CW\*(C`exec()\*(C'\fR. This |
3420 | up/change the process environment, followed by a call to \f(CW\*(C`exec()\*(C'\fR. This |
3418 | sequence should be handled by libev without any problems. |
3421 | sequence should be handled by libev without any problems. |
3419 | .PP |
3422 | .PP |
3420 | This changes when the application actually wants to do event handling |
3423 | This changes when the application actually wants to do event handling |
3421 | in the child, or both parent in child, in effect \*(L"continuing\*(R" after the |
3424 | in the child, or both parent in child, in effect \*(L"continuing\*(R" after the |
… | |
… | |
4245 | \& void operator() (ev::io &w, int revents) |
4248 | \& void operator() (ev::io &w, int revents) |
4246 | \& { |
4249 | \& { |
4247 | \& ... |
4250 | \& ... |
4248 | \& } |
4251 | \& } |
4249 | \& } |
4252 | \& } |
4250 | \& |
4253 | \& |
4251 | \& myfunctor f; |
4254 | \& myfunctor f; |
4252 | \& |
4255 | \& |
4253 | \& ev::io w; |
4256 | \& ev::io w; |
4254 | \& w.set (&f); |
4257 | \& w.set (&f); |
4255 | .Ve |
4258 | .Ve |