1 | .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.30) |
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 "2016-11-16" "libev-4.23" "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, although you still |
547 | forget about forgetting to tell libev about forking, although you still |
547 | have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag. |
548 | have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag. |
548 | .Sp |
549 | .Sp |
… | |
… | |
2250 | .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)" |
2251 | .PD 0 |
2252 | .PD 0 |
2252 | .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 |
2253 | .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)" |
2254 | .PD |
2255 | .PD |
2255 | 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 |
2256 | 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 |
2257 | reached. If it is positive, then the timer will automatically be |
2258 | automatically be stopped once the timeout is reached. If it is positive, |
2258 | 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 |
2259 | until stopped manually. |
2260 | seconds later, again, and again, until stopped manually. |
2260 | .Sp |
2261 | .Sp |
2261 | 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 |
2262 | 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 |
2263 | trigger at exactly 10 second intervals. If, however, your program cannot |
2264 | trigger at exactly 10 second intervals. If, however, your program cannot |
2264 | 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 |
… | |
… | |
2361 | \&\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 |
2362 | it, as it uses a relative timeout). |
2363 | it, as it uses a relative timeout). |
2363 | .PP |
2364 | .PP |
2364 | \&\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 |
2365 | 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 |
2366 | 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 |
2367 | those cannot react to time jumps. |
2368 | watchers, as those cannot react to time jumps. |
2368 | .PP |
2369 | .PP |
2369 | 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 |
2370 | 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 |
2371 | 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 |
2372 | 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 |
… | |
… | |
2461 | .Sp |
2462 | .Sp |
2462 | \&\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 |
2463 | 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. |
2464 | .Sp |
2465 | .Sp |
2465 | 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 |
2466 | 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 |
2467 | 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 |
2468 | 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 |
2469 | 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). |
2470 | .RE |
2491 | .RE |
2471 | .RS 4 |
2492 | .RS 4 |
2472 | .RE |
2493 | .RE |
2473 | .IP "ev_periodic_again (loop, ev_periodic *)" 4 |
2494 | .IP "ev_periodic_again (loop, ev_periodic *)" 4 |
2474 | .IX Item "ev_periodic_again (loop, ev_periodic *)" |
2495 | .IX Item "ev_periodic_again (loop, ev_periodic *)" |
… | |
… | |
3644 | 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 |
3645 | notification, and the callback being invoked. |
3666 | notification, and the callback being invoked. |
3646 | .SH "OTHER FUNCTIONS" |
3667 | .SH "OTHER FUNCTIONS" |
3647 | .IX Header "OTHER FUNCTIONS" |
3668 | .IX Header "OTHER FUNCTIONS" |
3648 | There are some other functions of possible interest. Described. Here. Now. |
3669 | There are some other functions of possible interest. Described. Here. Now. |
3649 | .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 |
3650 | .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)" |
3651 | 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 |
3652 | callback on whichever event happens first and automatically stops both |
3673 | callback on whichever event happens first and automatically stops both |
3653 | 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 |
3654 | 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 |
3655 | more watchers yourself. |
3676 | more watchers yourself. |
… | |
… | |
4105 | 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 |
4106 | 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 |
4107 | will work fine. |
4128 | will work fine. |
4108 | .PP |
4129 | .PP |
4109 | Proper exception specifications might have to be added to callbacks passed |
4130 | Proper exception specifications might have to be added to callbacks passed |
4110 | to libev: exceptions may be thrown only from watcher callbacks, all |
4131 | to libev: exceptions may be thrown only from watcher callbacks, all other |
4111 | other callbacks (allocator, syserr, loop acquire/release and periodic |
4132 | callbacks (allocator, syserr, loop acquire/release and periodic reschedule |
4112 | 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 |
4113 | ()\*(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 |
4114 | 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: |
4115 | .PP |
4136 | .PP |
4116 | .Vb 6 |
4137 | .Vb 6 |
4117 | \& static void |
4138 | \& static void |
4118 | \& fatal_error (const char *msg) EV_THROW |
4139 | \& fatal_error (const char *msg) EV_NOEXCEPT |
4119 | \& { |
4140 | \& { |
4120 | \& perror (msg); |
4141 | \& perror (msg); |
4121 | \& abort (); |
4142 | \& abort (); |
4122 | \& } |
4143 | \& } |
4123 | \& |
4144 | \& |
… | |
… | |
4521 | \& ev_vars.h |
4542 | \& ev_vars.h |
4522 | \& ev_wrap.h |
4543 | \& ev_wrap.h |
4523 | \& |
4544 | \& |
4524 | \& ev_win32.c required on win32 platforms only |
4545 | \& ev_win32.c required on win32 platforms only |
4525 | \& |
4546 | \& |
4526 | \& ev_select.c only when select backend is enabled (which is enabled by default) |
4547 | \& ev_select.c only when select backend is enabled |
4527 | \& ev_poll.c only when poll backend is enabled (disabled by default) |
4548 | \& ev_poll.c only when poll backend is enabled |
4528 | \& ev_epoll.c only when the epoll backend is enabled (disabled by default) |
4549 | \& ev_epoll.c only when the epoll backend is enabled |
4529 | \& ev_kqueue.c only when the kqueue backend is enabled (disabled by default) |
4550 | \& ev_kqueue.c only when the kqueue backend is enabled |
4530 | \& 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 |
4531 | .Ve |
4552 | .Ve |
4532 | .PP |
4553 | .PP |
4533 | \&\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 |
4534 | to compile this single file. |
4555 | to compile this single file. |
4535 | .PP |
4556 | .PP |