From 2fe61dad541713937487cf1a3c561f36daa669b9 Mon Sep 17 00:00:00 2001 From: Keith Rarick Date: Mon, 3 Nov 2008 14:39:13 -0800 Subject: [PATCH] Revert "Avoid a soonest_job call when we know we're timing out by request." This reverts commit 1ca60f54006364ee7f002603b8324c34906951c6. The user-requested timeout might happen later than the soonest job timeout. They must be compared. --- conn.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conn.c b/conn.c index fd64007..02602e4 100644 --- a/conn.c +++ b/conn.c @@ -149,21 +149,21 @@ has_reserved_job(conn c) int conn_set_evq(conn c, const int events, evh handler) { - int r, margin = 0, should_timeout = 0; + int r, margin = 0, should_timeout=0; struct timeval tv = {INT_MAX, 0}; event_set(&c->evq, c->fd, events, handler, c); if (conn_waiting(c)) margin = 1; - if (c->pending_timeout >= 0) { - tv.tv_sec = c->pending_timeout; - should_timeout=1; - } - if (should_timeout == 0 && has_reserved_job(c)) { + if (has_reserved_job(c)) { time_t t = soonest_job(c)->deadline - time(NULL) - margin; tv.tv_sec = t > 0 ? t : 0; should_timeout = 1; } + if (c->pending_timeout >= 0) { + tv.tv_sec = min(tv.tv_sec, c->pending_timeout); + should_timeout = 1; + } r = event_add(&c->evq, should_timeout ? &tv : NULL); if (r == -1) return twarn("event_add() err %d", errno), -1; -- 2.11.4.GIT