X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Ftest%2Frun-15-timeout.c;h=a4ab23add0abed3b0a3bcc5d536983db458ce8b5;hb=ba89419ac9074d930eec7ba72c378831c56ed060;hp=e4f3be6d6fffbfa997fd2f670b7ac925fbdbb5ba;hpb=318f717e34e4735e5397bee24dbbee69205be82b;p=ccan diff --git a/ccan/io/test/run-15-timeout.c b/ccan/io/test/run-15-timeout.c index e4f3be6d..a4ab23ad 100644 --- a/ccan/io/test/run-15-timeout.c +++ b/ccan/io/test/run-15-timeout.c @@ -47,8 +47,7 @@ static struct io_plan *init_conn(struct io_conn *conn, struct data *d) d->conn = conn; io_set_finish(conn, finish_ok, d); - timer_add(&d->timers, &d->timer, - timeabs_add(time_now(), time_from_usec(d->timeout_usec))); + timer_addrel(&d->timers, &d->timer, time_from_usec(d->timeout_usec)); return io_read(conn, d->buf, sizeof(d->buf), no_timeout, d); } @@ -90,14 +89,15 @@ int main(void) struct data *d = malloc(sizeof(*d)); struct addrinfo *addrinfo; struct io_listener *l; - struct list_head expired; + struct timer *expired; int fd, status; /* This is how many tests you plan to run */ plan_tests(21); d->state = 0; d->timeout_usec = 100000; - timers_init(&d->timers, time_now()); + timers_init(&d->timers, time_mono()); + timer_init(&d->timer); fd = make_listen_fd(PORT, &addrinfo); ok1(fd >= 0); l = io_new_listener(NULL, fd, init_conn, d); @@ -129,15 +129,15 @@ int main(void) ok1(io_loop(&d->timers, &expired) == NULL); /* One element, d->timer. */ - ok1(list_pop(&expired, struct timer, list) == &d->timer); - ok1(list_empty(&expired)); + ok1(expired == &d->timer); + ok1(!timers_expire(&d->timers, time_mono())); ok1(d->state == 1); io_close(d->conn); /* Finished will be called, d will be returned */ ok1(io_loop(&d->timers, &expired) == d); - ok1(list_empty(&expired)); + ok1(expired == NULL); ok1(d->state == 2); /* It should have died. */ @@ -174,7 +174,7 @@ int main(void) } ok1(io_loop(&d->timers, &expired) == d); ok1(d->state == 3); - ok1(list_empty(&expired)); + ok1(expired == NULL); ok1(wait(&status)); ok1(WIFEXITED(status)); ok1(WEXITSTATUS(status) >= sizeof(d->buf));