|
|
@ -2227,8 +2227,8 @@ it, as it uses a relative timeout). |
|
|
|
|
|
|
|
C<ev_periodic> watchers can also be used to implement vastly more complex |
|
|
|
timers, such as triggering an event on each "midnight, local time", or |
|
|
|
other complicated rules. This cannot be done with C<ev_timer> watchers, as |
|
|
|
those cannot react to time jumps. |
|
|
|
other complicated rules. This cannot easily be done with C<ev_timer> |
|
|
|
watchers, as those cannot react to time jumps. |
|
|
|
|
|
|
|
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 |
|
|
@ -2324,10 +2324,28 @@ NOTE: I<< This callback must always return a time that is higher than or |
|
|
|
equal to the passed C<now> value >>. |
|
|
|
|
|
|
|
This can be used to create very complex timers, such as a timer that |
|
|
|
triggers on "next midnight, local time". To do this, you would calculate the |
|
|
|
next midnight after C<now> 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 "next midnight, local time". To do this, you would calculate |
|
|
|
the next midnight after C<now> and return the timestamp value for |
|
|
|
this. Here is a (completely untested, no error checking) example on how to |
|
|
|
do this: |
|
|
|
|
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
Note: this code might run into trouble on days that have more then two |
|
|
|
midnights (beginning and end). |
|
|
|
|
|
|
|
=back |
|
|
|
|
|
|
|