--- libev/ev.3 2018/07/28 04:15:15 1.108 +++ libev/ev.3 2018/12/21 07:03:02 1.109 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "LIBEV 3" -.TH LIBEV 3 "2017-11-14" "libev-4.24" "libev - high performance full featured event loop" +.TH LIBEV 3 "2018-12-21" "libev-4.25" "libev - high performance full featured event loop" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -2253,11 +2253,11 @@ .IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4 .IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" .PD -Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds. If \f(CW\*(C`repeat\*(C'\fR -is \f(CW0.\fR, then it will automatically be stopped once the timeout is -reached. If it is positive, then the timer will automatically be -configured to trigger again \f(CW\*(C`repeat\*(C'\fR seconds later, again, and again, -until stopped manually. +Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds (fractional and +negative values are supported). If \f(CW\*(C`repeat\*(C'\fR is \f(CW0.\fR, then it will +automatically be stopped once the timeout is reached. If it is positive, +then the timer will automatically be configured to trigger again \f(CW\*(C`repeat\*(C'\fR +seconds later, again, and again, until stopped manually. .Sp The timer itself will do a best-effort at avoiding drift, that is, if you configure a timer to trigger every 10 seconds, then it will normally @@ -2364,8 +2364,8 @@ .PP \&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex timers, such as triggering an event on each \*(L"midnight, local time\*(R", or -other complicated rules. This cannot be done with \f(CW\*(C`ev_timer\*(C'\fR watchers, as -those cannot react to time jumps. +other complicated rules. This cannot easily be done with \f(CW\*(C`ev_timer\*(C'\fR +watchers, as those cannot react to time jumps. .PP As with timers, the callback is guaranteed to be invoked only when the point in time where it is supposed to trigger has passed. If multiple @@ -2464,10 +2464,30 @@ equal to the passed \f(CI\*(C`now\*(C'\fI value\fR. .Sp This can be used to create very complex timers, such as a timer that -triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate the -next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for this. How -you do this is, again, up to you (but it is not trivial, which is the main -reason I omitted it as an example). +triggers on \*(L"next midnight, local time\*(R". To do this, you would calculate +the next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for +this. Here is a (completely untested, no error checking) example on how to +do this: +.Sp +.Vb 1 +\& #include +\& +\& static ev_tstamp +\& my_rescheduler (ev_periodic *w, ev_tstamp now) +\& { +\& time_t tnow = (time_t)now; +\& struct tm tm; +\& localtime_r (&tnow, &tm); +\& +\& tm.tm_sec = tm.tm_min = tm.tm_hour = 0; // midnight current day +\& ++tm.tm_mday; // midnight next day +\& +\& return mktime (&tm); +\& } +.Ve +.Sp +Note: this code might run into trouble on days that have more then two +midnights (beginning and end). .RE .RS 4 .RE @@ -3647,8 +3667,8 @@ .SH "OTHER FUNCTIONS" .IX Header "OTHER FUNCTIONS" There are some other functions of possible interest. Described. Here. Now. -.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 -.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" +.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)" 4 +.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback, arg)" This function combines a simple timer and an I/O watcher, calls your callback on whichever event happens first and automatically stops both watchers. This is useful if you want to wait for a single event on an fd @@ -4108,15 +4128,15 @@ will work fine. .PP Proper exception specifications might have to be added to callbacks passed -to libev: exceptions may be thrown only from watcher callbacks, all -other callbacks (allocator, syserr, loop acquire/release and periodic -reschedule callbacks) must not throw exceptions, and might need a \f(CW\*(C`throw -()\*(C'\fR specification. If you have code that needs to be compiled as both C -and \*(C+ you can use the \f(CW\*(C`EV_THROW\*(C'\fR macro for this: +to libev: exceptions may be thrown only from watcher callbacks, all other +callbacks (allocator, syserr, loop acquire/release and periodic reschedule +callbacks) must not throw exceptions, and might need a \f(CW\*(C`noexcept\*(C'\fR +specification. If you have code that needs to be compiled as both C and +\&\*(C+ you can use the \f(CW\*(C`EV_NOEXCEPT\*(C'\fR macro for this: .PP .Vb 6 \& static void -\& fatal_error (const char *msg) EV_THROW +\& fatal_error (const char *msg) EV_NOEXCEPT \& { \& perror (msg); \& abort ();