- int i, r, timeout = INT_MAX;
- struct timespec now;
- bool some_timeouts = false;
-
- if (timeouts.base) {
- struct timespec first;
- struct list_head expired;
- struct io_timeout *t;
-
- now = time_now();
-
- /* Call functions for expired timers. */
- timers_expire(&timeouts, now, &expired);
- while ((t = list_pop(&expired, struct io_timeout, timer.list))) {
- struct io_conn *conn = t->conn;
- /* Clear, in case timer re-adds */
- t->conn = NULL;
- set_current(conn);
- set_plan(conn, t->next(conn, t->next_arg));
- some_timeouts = true;
- }
-
- /* Now figure out how long to wait for the next one. */
- if (timer_earliest(&timeouts, &first)) {
- uint64_t f = time_to_msec(time_sub(first, now));
- if (f < INT_MAX)
- timeout = f;
- }
- }