+ int i, r, timeout = INT_MAX;
+ struct timespec now;
+
+ 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;
+ backend_set_state(conn, t->next(conn, t->next_arg));
+ }
+
+ /* 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;
+ }
+ }