X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Fpoll.c;h=cddc3cacd266e5b80392d91af367d689da093bd6;hp=3266bdb2f5c737baecde62870445f90597895cfe;hb=aae40e493625a07f4ac95476664447546b28661a;hpb=f3c92802bfdb388f8c191cd1c682f90bc485b357 diff --git a/ccan/io/poll.c b/ccan/io/poll.c index 3266bdb2..cddc3cac 100644 --- a/ccan/io/poll.c +++ b/ccan/io/poll.c @@ -16,6 +16,14 @@ static struct pollfd *pollfds = NULL; static struct fd **fds = NULL; static LIST_HEAD(closing); static LIST_HEAD(always); +static struct timeabs (*nowfn)(void) = time_now; + +struct timeabs (*io_time_override(struct timeabs (*now)(void)))(void) +{ + struct timeabs (*old)(void) = nowfn; + nowfn = now; + return old; +} static bool add_fd(struct fd *fd, short events) { @@ -222,16 +230,16 @@ static bool handle_always(void) } /* This is the main loop. */ -void *io_loop(struct timers *timers, struct list_head *expired) +void *io_loop(struct timers *timers, struct timer **expired) { void *ret; /* if timers is NULL, expired must be. If not, not. */ assert(!timers == !expired); - /* Make sure this is empty if we exit for some other reason. */ + /* Make sure this is NULL if we exit for some other reason. */ if (expired) - list_head_init(expired); + *expired = NULL; while (!io_loop_return) { int i, r, ms_timeout = -1; @@ -256,11 +264,11 @@ void *io_loop(struct timers *timers, struct list_head *expired) if (timers) { struct timeabs now, first; - now = time_now(); + now = nowfn(); /* Call functions for expired timers. */ - timers_expire(timers, now, expired); - if (!list_empty(expired)) + *expired = timers_expire(timers, now); + if (*expired) break; /* Now figure out how long to wait for the next one. */