1 | .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) |
1 | .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) |
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 "2018-12-21" "libev-4.25" "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" |
… | |
… | |
536 | make libev check for a fork in each iteration by enabling this flag. |
536 | make libev check for a fork in each iteration by enabling this flag. |
537 | .Sp |
537 | .Sp |
538 | This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop, |
538 | This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop, |
539 | and thus this might slow down your event loop if you do a lot of loop |
539 | and thus this might slow down your event loop if you do a lot of loop |
540 | iterations and little real work, but is usually not noticeable (on my |
540 | iterations and little real work, but is usually not noticeable (on my |
541 | GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn sequence |
541 | GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn |
542 | without a system call and thus \fIvery\fR fast, but my GNU/Linux system also has |
542 | sequence without a system call and thus \fIvery\fR fast, but my GNU/Linux |
543 | \&\f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). |
543 | system also has \f(CW\*(C`pthread_atfork\*(C'\fR which is even faster). (Update: glibc |
|
|
544 | versions 2.25 apparently removed the \f(CW\*(C`getpid\*(C'\fR optimisation again). |
544 | .Sp |
545 | .Sp |
545 | The big advantage of this flag is that you can forget about fork (and |
546 | The big advantage of this flag is that you can forget about fork (and |
546 | forget about forgetting to tell libev about forking) when you use this |
547 | forget about forgetting to tell libev about forking, although you still |
547 | flag. |
548 | have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag. |
548 | .Sp |
549 | .Sp |
549 | This flag setting cannot be overridden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR |
550 | This flag setting cannot be overridden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR |
550 | environment variable. |
551 | environment variable. |
551 | .ie n .IP """EVFLAG_NOINOTIFY""" 4 |
552 | .ie n .IP """EVFLAG_NOINOTIFY""" 4 |
552 | .el .IP "\f(CWEVFLAG_NOINOTIFY\fR" 4 |
553 | .el .IP "\f(CWEVFLAG_NOINOTIFY\fR" 4 |
… | |
… | |
810 | except in the rare occasion where you really need to free its resources. |
811 | 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 |
812 | 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. |
813 | and \f(CW\*(C`ev_loop_destroy\*(C'\fR. |
813 | .IP "ev_loop_fork (loop)" 4 |
814 | .IP "ev_loop_fork (loop)" 4 |
814 | .IX Item "ev_loop_fork (loop)" |
815 | .IX Item "ev_loop_fork (loop)" |
815 | This function sets a flag that causes subsequent \f(CW\*(C`ev_run\*(C'\fR iterations to |
816 | 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 |
817 | 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 |
818 | 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 |
819 | 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. |
820 | sense after forking, in the child process. You \fImust\fR call it (or use |
|
|
821 | \&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR) in the child before resuming or calling \f(CW\*(C`ev_run\*(C'\fR. |
|
|
822 | .Sp |
|
|
823 | In addition, if you want to reuse a loop (via this function or |
|
|
824 | \&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR), you \fIalso\fR have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR. |
820 | .Sp |
825 | .Sp |
821 | Again, you \fIhave\fR to call it on \fIany\fR loop that you want to re-use after |
826 | 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 |
827 | 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 |
828 | because some kernel interfaces *cough* \fIkqueue\fR *cough* do funny things |
824 | during fork. |
829 | during fork. |
… | |
… | |
2161 | .PP |
2166 | .PP |
2162 | The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR |
2167 | 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 |
2168 | 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 |
2169 | 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 |
2170 | 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: |
2171 | timeout on the current time, use something like the following to adjust |
|
|
2172 | for it: |
2167 | .PP |
2173 | .PP |
2168 | .Vb 1 |
2174 | .Vb 1 |
2169 | \& ev_timer_set (&timer, after + ev_now () \- ev_time (), 0.); |
2175 | \& ev_timer_set (&timer, after + (ev_time () \- ev_now ()), 0.); |
2170 | .Ve |
2176 | .Ve |
2171 | .PP |
2177 | .PP |
2172 | If the event loop is suspended for a long time, you can also force an |
2178 | 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 |
2179 | update of the time returned by \f(CW\*(C`ev_now ()\*(C'\fR by calling \f(CW\*(C`ev_now_update |
2174 | ()\*(C'\fR. |
2180 | ()\*(C'\fR, although that will push the event time of all outstanding events |
|
|
2181 | further into the future. |
2175 | .PP |
2182 | .PP |
2176 | \fIThe special problem of unsynchronised clocks\fR |
2183 | \fIThe special problem of unsynchronised clocks\fR |
2177 | .IX Subsection "The special problem of unsynchronised clocks" |
2184 | .IX Subsection "The special problem of unsynchronised clocks" |
2178 | .PP |
2185 | .PP |
2179 | Modern systems have a variety of clocks \- libev itself uses the normal |
2186 | Modern systems have a variety of clocks \- libev itself uses the normal |
… | |
… | |
2244 | .IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" |
2251 | .IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" |
2245 | .PD 0 |
2252 | .PD 0 |
2246 | .IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 |
2253 | .IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 |
2247 | .IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" |
2254 | .IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" |
2248 | .PD |
2255 | .PD |
2249 | Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds. If \f(CW\*(C`repeat\*(C'\fR |
2256 | Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds (fractional and |
2250 | is \f(CW0.\fR, then it will automatically be stopped once the timeout is |
2257 | negative values are supported). If \f(CW\*(C`repeat\*(C'\fR is \f(CW0.\fR, then it will |
2251 | reached. If it is positive, then the timer will automatically be |
2258 | automatically be stopped once the timeout is reached. If it is positive, |
2252 | configured to trigger again \f(CW\*(C`repeat\*(C'\fR seconds later, again, and again, |
2259 | then the timer will automatically be configured to trigger again \f(CW\*(C`repeat\*(C'\fR |
2253 | until stopped manually. |
2260 | seconds later, again, and again, until stopped manually. |
2254 | .Sp |
2261 | .Sp |
2255 | The timer itself will do a best-effort at avoiding drift, that is, if |
2262 | The timer itself will do a best-effort at avoiding drift, that is, if |
2256 | you configure a timer to trigger every 10 seconds, then it will normally |
2263 | you configure a timer to trigger every 10 seconds, then it will normally |
2257 | trigger at exactly 10 second intervals. If, however, your program cannot |
2264 | trigger at exactly 10 second intervals. If, however, your program cannot |
2258 | keep up with the timer (because it takes longer than those 10 seconds to |
2265 | keep up with the timer (because it takes longer than those 10 seconds to |
… | |
… | |
2340 | Periodic watchers are also timers of a kind, but they are very versatile |
2347 | Periodic watchers are also timers of a kind, but they are very versatile |
2341 | (and unfortunately a bit complex). |
2348 | (and unfortunately a bit complex). |
2342 | .PP |
2349 | .PP |
2343 | Unlike \f(CW\*(C`ev_timer\*(C'\fR, periodic watchers are not based on real time (or |
2350 | Unlike \f(CW\*(C`ev_timer\*(C'\fR, periodic watchers are not based on real time (or |
2344 | relative time, the physical time that passes) but on wall clock time |
2351 | relative time, the physical time that passes) but on wall clock time |
2345 | (absolute time, the thing you can read on your calender or clock). The |
2352 | (absolute time, the thing you can read on your calendar or clock). The |
2346 | difference is that wall clock time can run faster or slower than real |
2353 | difference is that wall clock time can run faster or slower than real |
2347 | time, and time jumps are not uncommon (e.g. when you adjust your |
2354 | time, and time jumps are not uncommon (e.g. when you adjust your |
2348 | wrist-watch). |
2355 | wrist-watch). |
2349 | .PP |
2356 | .PP |
2350 | You can tell a periodic watcher to trigger after some specific point |
2357 | You can tell a periodic watcher to trigger after some specific point |
… | |
… | |
2355 | \&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting |
2362 | \&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting |
2356 | it, as it uses a relative timeout). |
2363 | it, as it uses a relative timeout). |
2357 | .PP |
2364 | .PP |
2358 | \&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex |
2365 | \&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex |
2359 | timers, such as triggering an event on each \*(L"midnight, local time\*(R", or |
2366 | timers, such as triggering an event on each \*(L"midnight, local time\*(R", or |
2360 | other complicated rules. This cannot be done with \f(CW\*(C`ev_timer\*(C'\fR watchers, as |
2367 | other complicated rules. This cannot easily be done with \f(CW\*(C`ev_timer\*(C'\fR |
2361 | those cannot react to time jumps. |
2368 | watchers, as those cannot react to time jumps. |
2362 | .PP |
2369 | .PP |
2363 | As with timers, the callback is guaranteed to be invoked only when the |
2370 | As with timers, the callback is guaranteed to be invoked only when the |
2364 | point in time where it is supposed to trigger has passed. If multiple |
2371 | point in time where it is supposed to trigger has passed. If multiple |
2365 | timers become ready during the same loop iteration then the ones with |
2372 | timers become ready during the same loop iteration then the ones with |
2366 | earlier time-out values are invoked before ones with later time-out values |
2373 | earlier time-out values are invoked before ones with later time-out values |
… | |
… | |
2455 | .Sp |
2462 | .Sp |
2456 | \&\s-1NOTE: \s0\fIThis callback must always return a time that is higher than or |
2463 | \&\s-1NOTE: \s0\fIThis callback must always return a time that is higher than or |
2457 | equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. |
2464 | equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. |
2458 | .Sp |
2465 | .Sp |
2459 | This can be used to create very complex timers, such as a timer that |
2466 | This can be used to create very complex timers, such as a timer that |
2460 | triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate the |
2467 | triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate |
2461 | next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for this. How |
2468 | the next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for |
2462 | you do this is, again, up to you (but it is not trivial, which is the main |
2469 | this. Here is a (completely untested, no error checking) example on how to |
2463 | reason I omitted it as an example). |
2470 | do this: |
|
|
2471 | .Sp |
|
|
2472 | .Vb 1 |
|
|
2473 | \& #include <time.h> |
|
|
2474 | \& |
|
|
2475 | \& static ev_tstamp |
|
|
2476 | \& my_rescheduler (ev_periodic *w, ev_tstamp now) |
|
|
2477 | \& { |
|
|
2478 | \& time_t tnow = (time_t)now; |
|
|
2479 | \& struct tm tm; |
|
|
2480 | \& localtime_r (&tnow, &tm); |
|
|
2481 | \& |
|
|
2482 | \& tm.tm_sec = tm.tm_min = tm.tm_hour = 0; // midnight current day |
|
|
2483 | \& ++tm.tm_mday; // midnight next day |
|
|
2484 | \& |
|
|
2485 | \& return mktime (&tm); |
|
|
2486 | \& } |
|
|
2487 | .Ve |
|
|
2488 | .Sp |
|
|
2489 | Note: this code might run into trouble on days that have more then two |
|
|
2490 | midnights (beginning and end). |
2464 | .RE |
2491 | .RE |
2465 | .RS 4 |
2492 | .RS 4 |
2466 | .RE |
2493 | .RE |
2467 | .IP "ev_periodic_again (loop, ev_periodic *)" 4 |
2494 | .IP "ev_periodic_again (loop, ev_periodic *)" 4 |
2468 | .IX Item "ev_periodic_again (loop, ev_periodic *)" |
2495 | .IX Item "ev_periodic_again (loop, ev_periodic *)" |
… | |
… | |
2553 | only within the same loop, i.e. you can watch for \f(CW\*(C`SIGINT\*(C'\fR in your |
2580 | 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 |
2581 | 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 |
2582 | \&\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. |
2583 | the moment, \f(CW\*(C`SIGCHLD\*(C'\fR is permanently tied to the default loop. |
2557 | .PP |
2584 | .PP |
2558 | When the first watcher gets started will libev actually register something |
2585 | 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 |
2586 | register something with the kernel. It thus coexists with your own signal |
2560 | you don't register any with libev for the same signal). |
2587 | handlers as long as you don't register any with libev for the same signal. |
2561 | .PP |
2588 | .PP |
2562 | If possible and supported, libev will install its handlers with |
2589 | 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 |
2590 | \&\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 |
2591 | 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 |
2592 | 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!" |
3075 | .IX Subsection "ev_prepare and ev_check - customise your event loop!" |
3049 | Prepare and check watchers are often (but not always) used in pairs: |
3076 | Prepare and check watchers are often (but not always) used in pairs: |
3050 | prepare watchers get invoked before the process blocks and check watchers |
3077 | prepare watchers get invoked before the process blocks and check watchers |
3051 | afterwards. |
3078 | afterwards. |
3052 | .PP |
3079 | .PP |
3053 | You \fImust not\fR call \f(CW\*(C`ev_run\*(C'\fR or similar functions that enter |
3080 | 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 |
3081 | 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 |
3082 | \&\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 |
3083 | 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, |
3084 | 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 |
3085 | \&\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. |
3086 | kind they will always be called in pairs bracketing the blocking call. |
3060 | .PP |
3087 | .PP |
3061 | Their main purpose is to integrate other event mechanisms into libev and |
3088 | 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 |
3089 | 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 |
3090 | variable changes, implement your own watchers, integrate net-snmp or a |
3064 | coroutine library and lots more. They are also occasionally useful if |
3091 | coroutine library and lots more. They are also occasionally useful if |
… | |
… | |
3358 | .PP |
3385 | .PP |
3359 | .Vb 3 |
3386 | .Vb 3 |
3360 | \& struct ev_loop *loop_hi = ev_default_init (0); |
3387 | \& struct ev_loop *loop_hi = ev_default_init (0); |
3361 | \& struct ev_loop *loop_lo = 0; |
3388 | \& struct ev_loop *loop_lo = 0; |
3362 | \& ev_embed embed; |
3389 | \& ev_embed embed; |
3363 | \& |
3390 | \& |
3364 | \& // see if there is a chance of getting one that works |
3391 | \& // see if there is a chance of getting one that works |
3365 | \& // (remember that a flags value of 0 means autodetection) |
3392 | \& // (remember that a flags value of 0 means autodetection) |
3366 | \& loop_lo = ev_embeddable_backends () & ev_recommended_backends () |
3393 | \& loop_lo = ev_embeddable_backends () & ev_recommended_backends () |
3367 | \& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ()) |
3394 | \& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ()) |
3368 | \& : 0; |
3395 | \& : 0; |
… | |
… | |
3384 | .PP |
3411 | .PP |
3385 | .Vb 3 |
3412 | .Vb 3 |
3386 | \& struct ev_loop *loop = ev_default_init (0); |
3413 | \& struct ev_loop *loop = ev_default_init (0); |
3387 | \& struct ev_loop *loop_socket = 0; |
3414 | \& struct ev_loop *loop_socket = 0; |
3388 | \& ev_embed embed; |
3415 | \& ev_embed embed; |
3389 | \& |
3416 | \& |
3390 | \& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) |
3417 | \& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) |
3391 | \& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) |
3418 | \& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) |
3392 | \& { |
3419 | \& { |
3393 | \& ev_embed_init (&embed, 0, loop_socket); |
3420 | \& ev_embed_init (&embed, 0, loop_socket); |
3394 | \& ev_embed_start (loop, &embed); |
3421 | \& ev_embed_start (loop, &embed); |
… | |
… | |
3411 | of course. |
3438 | of course. |
3412 | .PP |
3439 | .PP |
3413 | \fIThe special problem of life after fork \- how is it possible?\fR |
3440 | \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?" |
3441 | .IX Subsection "The special problem of life after fork - how is it possible?" |
3415 | .PP |
3442 | .PP |
3416 | Most uses of \f(CW\*(C`fork()\*(C'\fR consist of forking, then some simple calls to set |
3443 | 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 |
3444 | 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. |
3445 | sequence should be handled by libev without any problems. |
3419 | .PP |
3446 | .PP |
3420 | This changes when the application actually wants to do event handling |
3447 | 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 |
3448 | in the child, or both parent in child, in effect \*(L"continuing\*(R" after the |
… | |
… | |
3638 | is a time window between the event loop checking and resetting the async |
3665 | is a time window between the event loop checking and resetting the async |
3639 | notification, and the callback being invoked. |
3666 | notification, and the callback being invoked. |
3640 | .SH "OTHER FUNCTIONS" |
3667 | .SH "OTHER FUNCTIONS" |
3641 | .IX Header "OTHER FUNCTIONS" |
3668 | .IX Header "OTHER FUNCTIONS" |
3642 | There are some other functions of possible interest. Described. Here. Now. |
3669 | There are some other functions of possible interest. Described. Here. Now. |
3643 | .IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 |
3670 | .IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)" 4 |
3644 | .IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" |
3671 | .IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)" |
3645 | This function combines a simple timer and an I/O watcher, calls your |
3672 | This function combines a simple timer and an I/O watcher, calls your |
3646 | callback on whichever event happens first and automatically stops both |
3673 | callback on whichever event happens first and automatically stops both |
3647 | watchers. This is useful if you want to wait for a single event on an fd |
3674 | watchers. This is useful if you want to wait for a single event on an fd |
3648 | or timeout without having to allocate/configure/start/stop/free one or |
3675 | or timeout without having to allocate/configure/start/stop/free one or |
3649 | more watchers yourself. |
3676 | more watchers yourself. |
… | |
… | |
4049 | files, \fImy_ev.h\fR and \fImy_ev.c\fR that include the respective libev files: |
4076 | files, \fImy_ev.h\fR and \fImy_ev.c\fR that include the respective libev files: |
4050 | .PP |
4077 | .PP |
4051 | .Vb 4 |
4078 | .Vb 4 |
4052 | \& // my_ev.h |
4079 | \& // my_ev.h |
4053 | \& #define EV_CB_DECLARE(type) struct my_coro *cb; |
4080 | \& #define EV_CB_DECLARE(type) struct my_coro *cb; |
4054 | \& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb); |
4081 | \& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb) |
4055 | \& #include "../libev/ev.h" |
4082 | \& #include "../libev/ev.h" |
4056 | \& |
4083 | \& |
4057 | \& // my_ev.c |
4084 | \& // my_ev.c |
4058 | \& #define EV_H "my_ev.h" |
4085 | \& #define EV_H "my_ev.h" |
4059 | \& #include "../libev/ev.c" |
4086 | \& #include "../libev/ev.c" |
… | |
… | |
4099 | The normal C \s-1API\s0 should work fine when used from \*(C+: both ev.h and the |
4126 | The normal C \s-1API\s0 should work fine when used from \*(C+: both ev.h and the |
4100 | libev sources can be compiled as \*(C+. Therefore, code that uses the C \s-1API\s0 |
4127 | libev sources can be compiled as \*(C+. Therefore, code that uses the C \s-1API\s0 |
4101 | will work fine. |
4128 | will work fine. |
4102 | .PP |
4129 | .PP |
4103 | Proper exception specifications might have to be added to callbacks passed |
4130 | Proper exception specifications might have to be added to callbacks passed |
4104 | to libev: exceptions may be thrown only from watcher callbacks, all |
4131 | to libev: exceptions may be thrown only from watcher callbacks, all other |
4105 | other callbacks (allocator, syserr, loop acquire/release and periodic |
4132 | callbacks (allocator, syserr, loop acquire/release and periodic reschedule |
4106 | reschedule callbacks) must not throw exceptions, and might need a \f(CW\*(C`throw |
4133 | callbacks) must not throw exceptions, and might need a \f(CW\*(C`noexcept\*(C'\fR |
4107 | ()\*(C'\fR specification. If you have code that needs to be compiled as both C |
4134 | specification. If you have code that needs to be compiled as both C and |
4108 | and \*(C+ you can use the \f(CW\*(C`EV_THROW\*(C'\fR macro for this: |
4135 | \&\*(C+ you can use the \f(CW\*(C`EV_NOEXCEPT\*(C'\fR macro for this: |
4109 | .PP |
4136 | .PP |
4110 | .Vb 6 |
4137 | .Vb 6 |
4111 | \& static void |
4138 | \& static void |
4112 | \& fatal_error (const char *msg) EV_THROW |
4139 | \& fatal_error (const char *msg) EV_NOEXCEPT |
4113 | \& { |
4140 | \& { |
4114 | \& perror (msg); |
4141 | \& perror (msg); |
4115 | \& abort (); |
4142 | \& abort (); |
4116 | \& } |
4143 | \& } |
4117 | \& |
4144 | \& |
… | |
… | |
4245 | \& void operator() (ev::io &w, int revents) |
4272 | \& void operator() (ev::io &w, int revents) |
4246 | \& { |
4273 | \& { |
4247 | \& ... |
4274 | \& ... |
4248 | \& } |
4275 | \& } |
4249 | \& } |
4276 | \& } |
4250 | \& |
4277 | \& |
4251 | \& myfunctor f; |
4278 | \& myfunctor f; |
4252 | \& |
4279 | \& |
4253 | \& ev::io w; |
4280 | \& ev::io w; |
4254 | \& w.set (&f); |
4281 | \& w.set (&f); |
4255 | .Ve |
4282 | .Ve |
… | |
… | |
4515 | \& ev_vars.h |
4542 | \& ev_vars.h |
4516 | \& ev_wrap.h |
4543 | \& ev_wrap.h |
4517 | \& |
4544 | \& |
4518 | \& ev_win32.c required on win32 platforms only |
4545 | \& ev_win32.c required on win32 platforms only |
4519 | \& |
4546 | \& |
4520 | \& ev_select.c only when select backend is enabled (which is enabled by default) |
4547 | \& ev_select.c only when select backend is enabled |
4521 | \& ev_poll.c only when poll backend is enabled (disabled by default) |
4548 | \& ev_poll.c only when poll backend is enabled |
4522 | \& ev_epoll.c only when the epoll backend is enabled (disabled by default) |
4549 | \& ev_epoll.c only when the epoll backend is enabled |
4523 | \& ev_kqueue.c only when the kqueue backend is enabled (disabled by default) |
4550 | \& ev_kqueue.c only when the kqueue backend is enabled |
4524 | \& ev_port.c only when the solaris port backend is enabled (disabled by default) |
4551 | \& ev_port.c only when the solaris port backend is enabled |
4525 | .Ve |
4552 | .Ve |
4526 | .PP |
4553 | .PP |
4527 | \&\fIev.c\fR includes the backend files directly when enabled, so you only need |
4554 | \&\fIev.c\fR includes the backend files directly when enabled, so you only need |
4528 | to compile this single file. |
4555 | to compile this single file. |
4529 | .PP |
4556 | .PP |
… | |
… | |
5406 | Libev assumes not only that all watcher pointers have the same internal |
5433 | Libev assumes not only that all watcher pointers have the same internal |
5407 | structure (guaranteed by \s-1POSIX\s0 but not by \s-1ISO C\s0 for example), but it also |
5434 | structure (guaranteed by \s-1POSIX\s0 but not by \s-1ISO C\s0 for example), but it also |
5408 | assumes that the same (machine) code can be used to call any watcher |
5435 | assumes that the same (machine) code can be used to call any watcher |
5409 | callback: The watcher callbacks have different type signatures, but libev |
5436 | callback: The watcher callbacks have different type signatures, but libev |
5410 | calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally. |
5437 | calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally. |
|
|
5438 | .IP "null pointers and integer zero are represented by 0 bytes" 4 |
|
|
5439 | .IX Item "null pointers and integer zero are represented by 0 bytes" |
|
|
5440 | Libev uses \f(CW\*(C`memset\*(C'\fR to initialise structs and arrays to \f(CW0\fR bytes, and |
|
|
5441 | relies on this setting pointers and integers to null. |
5411 | .IP "pointer accesses must be thread-atomic" 4 |
5442 | .IP "pointer accesses must be thread-atomic" 4 |
5412 | .IX Item "pointer accesses must be thread-atomic" |
5443 | .IX Item "pointer accesses must be thread-atomic" |
5413 | Accessing a pointer value must be atomic, it must both be readable and |
5444 | Accessing a pointer value must be atomic, it must both be readable and |
5414 | writable in one piece \- this is the case on all current architectures. |
5445 | writable in one piece \- this is the case on all current architectures. |
5415 | .ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4 |
5446 | .ie n .IP """sig_atomic_t volatile"" must be thread-atomic as well" 4 |