… | |
… | |
2029 | |
2029 | |
2030 | The relative timeouts are calculated relative to the C<ev_now ()> |
2030 | The relative timeouts are calculated relative to the C<ev_now ()> |
2031 | time. This is usually the right thing as this timestamp refers to the time |
2031 | time. This is usually the right thing as this timestamp refers to the time |
2032 | of the event triggering whatever timeout you are modifying/starting. If |
2032 | of the event triggering whatever timeout you are modifying/starting. If |
2033 | you suspect event processing to be delayed and you I<need> to base the |
2033 | you suspect event processing to be delayed and you I<need> to base the |
2034 | timeout on the current time, use something like this to adjust for this: |
2034 | timeout on the current time, use something like the following to adjust |
|
|
2035 | for it: |
2035 | |
2036 | |
2036 | ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); |
2037 | ev_timer_set (&timer, after + (ev_time () - ev_now ()), 0.); |
2037 | |
2038 | |
2038 | If the event loop is suspended for a long time, you can also force an |
2039 | If the event loop is suspended for a long time, you can also force an |
2039 | update of the time returned by C<ev_now ()> by calling C<ev_now_update |
2040 | update of the time returned by C<ev_now ()> by calling C<ev_now_update |
2040 | ()>. |
2041 | ()>, although that will push the event time of all outstanding events |
|
|
2042 | further into the future. |
2041 | |
2043 | |
2042 | =head3 The special problem of unsynchronised clocks |
2044 | =head3 The special problem of unsynchronised clocks |
2043 | |
2045 | |
2044 | Modern systems have a variety of clocks - libev itself uses the normal |
2046 | Modern systems have a variety of clocks - libev itself uses the normal |
2045 | "wall clock" clock and, if available, the monotonic clock (to avoid time |
2047 | "wall clock" clock and, if available, the monotonic clock (to avoid time |
… | |
… | |
3898 | To embed libev, see L</EMBEDDING>, but in short, it's easiest to create two |
3900 | To embed libev, see L</EMBEDDING>, but in short, it's easiest to create two |
3899 | files, F<my_ev.h> and F<my_ev.c> that include the respective libev files: |
3901 | files, F<my_ev.h> and F<my_ev.c> that include the respective libev files: |
3900 | |
3902 | |
3901 | // my_ev.h |
3903 | // my_ev.h |
3902 | #define EV_CB_DECLARE(type) struct my_coro *cb; |
3904 | #define EV_CB_DECLARE(type) struct my_coro *cb; |
3903 | #define EV_CB_INVOKE(watcher) switch_to ((watcher)->cb); |
3905 | #define EV_CB_INVOKE(watcher) switch_to ((watcher)->cb) |
3904 | #include "../libev/ev.h" |
3906 | #include "../libev/ev.h" |
3905 | |
3907 | |
3906 | // my_ev.c |
3908 | // my_ev.c |
3907 | #define EV_H "my_ev.h" |
3909 | #define EV_H "my_ev.h" |
3908 | #include "../libev/ev.c" |
3910 | #include "../libev/ev.c" |