mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-17 19:31:18 +00:00
Keep timer deadlines between calls to uev_run()
Timers never expire when the event loop is run one iteration at a time
and something else keeps it busy, e.g., when polled from another event
loop:
uev_run(ctx, UEV_ONCE | UEV_NONBLOCK);
Every call to uev_run() starts all timers over from their full timeout.
Start dormant timers on the first call only. A caller that wants a
timer restarted for each call must now use uev_timer_set().
Closes #36
This commit is contained in:
1 parent
354cdcaf7a
commit
09d9b6ba04
6 files changed
+53
-10
No files matched your search
@@ -7,6 +7,7 @@ cronrun
|
||||
cronstart
|
||||
error
|
||||
io
|
||||
resume
|
||||
signal
|
||||
stdin
|
||||
timer
|
||||
|
||||
@@ -12,6 +12,7 @@ TESTS += cronrun
|
||||
TESTS += cronstart
|
||||
TESTS += error
|
||||
TESTS += io
|
||||
TESTS += resume
|
||||
TESTS += signal
|
||||
TESTS += stdin
|
||||
TESTS += timer
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Verifies that timers keep their deadline between calls to uev_run() */
|
||||
#include "check.h"
|
||||
|
||||
static int fired;
|
||||
|
||||
static void cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
fired++;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
int i;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(uev_timer_init(&ctx, &w, cb, NULL, 50, 0) == 0);
|
||||
|
||||
for (i = 0; i < 15; i++) {
|
||||
fail_unless(uev_run(&ctx, UEV_ONCE | UEV_NONBLOCK) == 0);
|
||||
usleep(10000);
|
||||
}
|
||||
fail_unless(fired == 1);
|
||||
|
||||
return uev_exit(&ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
Reference in new issue
Block a user