ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.443 by root, Thu Aug 30 21:51:15 2018 UTC vs.
Revision 1.444 by root, Mon Oct 29 00:00:22 2018 UTC

2225C<ev_timer>, which would still trigger roughly 10 seconds after starting 2225C<ev_timer>, which would still trigger roughly 10 seconds after starting
2226it, as it uses a relative timeout). 2226it, as it uses a relative timeout).
2227 2227
2228C<ev_periodic> watchers can also be used to implement vastly more complex 2228C<ev_periodic> watchers can also be used to implement vastly more complex
2229timers, such as triggering an event on each "midnight, local time", or 2229timers, such as triggering an event on each "midnight, local time", or
2230other complicated rules. This cannot be done with C<ev_timer> watchers, as 2230other complicated rules. This cannot easily be done with C<ev_timer>
2231those cannot react to time jumps. 2231watchers, as those cannot react to time jumps.
2232 2232
2233As with timers, the callback is guaranteed to be invoked only when the 2233As with timers, the callback is guaranteed to be invoked only when the
2234point in time where it is supposed to trigger has passed. If multiple 2234point in time where it is supposed to trigger has passed. If multiple
2235timers become ready during the same loop iteration then the ones with 2235timers become ready during the same loop iteration then the ones with
2236earlier time-out values are invoked before ones with later time-out values 2236earlier time-out values are invoked before ones with later time-out values
2322 2322
2323NOTE: I<< This callback must always return a time that is higher than or 2323NOTE: I<< This callback must always return a time that is higher than or
2324equal to the passed C<now> value >>. 2324equal to the passed C<now> value >>.
2325 2325
2326This can be used to create very complex timers, such as a timer that 2326This can be used to create very complex timers, such as a timer that
2327triggers on "next midnight, local time". To do this, you would calculate the 2327triggers on "next midnight, local time". To do this, you would calculate
2328next midnight after C<now> and return the timestamp value for this. How 2328the next midnight after C<now> and return the timestamp value for
2329you do this is, again, up to you (but it is not trivial, which is the main 2329this. Here is a (completely untested, no error checking) example on how to
2330reason I omitted it as an example). 2330do this:
2331
2332 #include <time.h>
2333
2334 static ev_tstamp
2335 my_rescheduler (ev_periodic *w, ev_tstamp now)
2336 {
2337 time_t tnow = (time_t)now;
2338 struct tm tm;
2339 localtime_r (&tnow, &tm);
2340
2341 tm.tm_sec = tm.tm_min = tm.tm_hour = 0; // midnight current day
2342 ++tm.tm_mday; // midnight next day
2343
2344 return mktime (&tm);
2345 }
2346
2347Note: this code might run into trouble on days that have more then two
2348midnights (beginning and end).
2331 2349
2332=back 2350=back
2333 2351
2334=item ev_periodic_again (loop, ev_periodic *) 2352=item ev_periodic_again (loop, ev_periodic *)
2335 2353

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines