Change isc_timer_reset() usage to never use expires argument

There were two places where expires argument (absolute isc_time_t value)
was being used.  Both places has been converted to use relative interval
argument in preparation of simplification and refactoring of isc_timer
API.
This commit is contained in:
Ondřej Surý 2022-03-11 22:34:45 +01:00 committed by Evan Hunt
parent c259cecc90
commit 27850a5ad2
3 changed files with 47 additions and 24 deletions

View file

@ -337,7 +337,6 @@ struct fetchctx {
isc_time_t expires;
isc_time_t expires_try_stale;
isc_time_t next_timeout;
isc_time_t final;
isc_interval_t interval;
dns_message_t *qmessage;
ISC_LIST(resquery_t) queries;
@ -1255,8 +1254,27 @@ update_edns_stats(resquery_t *query) {
*/
static inline isc_result_t
fctx_starttimer(fetchctx_t *fctx) {
return (isc_timer_reset(fctx->timer, isc_timertype_once, &fctx->final,
NULL, true));
isc_interval_t interval;
isc_time_t now;
isc_time_t expires;
isc_interval_set(&interval, 2, 0);
isc_time_add(&fctx->expires, &interval, &expires);
isc_time_now(&now);
if (isc_time_compare(&expires, &now) <= 0) {
isc_interval_set(&interval, 0, 1);
} else {
isc_time_t tmp;
isc_interval_set(&interval, isc_time_seconds(&now),
isc_time_nanoseconds(&now));
isc_time_subtract(&expires, &interval, &tmp);
isc_interval_set(&interval, isc_time_seconds(&tmp),
isc_time_nanoseconds(&tmp));
}
return (isc_timer_reset(fctx->timer, isc_timertype_once, NULL,
&interval, true));
}
static inline void
@ -4533,6 +4551,13 @@ fctx_start(isc_task_t *task, isc_event_t *event) {
UNLOCK(&res->buckets[bucketnum].lock);
/*
* As a backstop, we also set a timer to stop the fetch
* if in-band netmgr timeouts don't work. It will fire two
* seconds after the fetch should have finished. (This
* should be enough of a gap to avoid the timer firing
* while a response is being processed normally.)
*/
result = fctx_starttimer(fctx);
if (result != ISC_R_SUCCESS) {
fctx_done(fctx, result, __LINE__);
@ -4836,22 +4861,6 @@ fctx_create(dns_resolver_t *res, isc_task_t *task, const dns_name_t *name,
goto cleanup_qmessage;
}
/*
* As a backstop, we also set a timer to stop the fetch
* if in-band netmgr timeouts don't work. It will fire two
* seconds after the fetch should have finished. (This
* should be enough of a gap to avoid the timer firing
* while a response is being processed normally.)
*/
isc_interval_set(&interval, 2, 0);
iresult = isc_time_add(&fctx->expires, &interval, &fctx->final);
if (iresult != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_time_add: %s",
isc_result_totext(iresult));
result = ISC_R_UNEXPECTED;
goto cleanup_qmessage;
}
/*
* Create an inactive timer to enforce maximum query
* lifetime. It will be made active when the fetch is

View file

@ -15279,11 +15279,25 @@ zone_settimer(dns_zone_t *zone, isc_time_t *now) {
isc_result_totext(result));
}
} else {
isc_interval_t interval;
if (isc_time_compare(&next, now) <= 0) {
next = *now;
isc_interval_set(&interval, 0, 1);
} else {
/*
* In theory, we could just type isc_interval_t to
* isc_time_t and back, but there's no such guarantee,
* so a safer method is being used here.
*/
isc_time_t tmp;
isc_interval_set(&interval, isc_time_seconds(now),
isc_time_nanoseconds(now));
isc_time_subtract(&next, &interval, &tmp);
isc_interval_set(&interval, isc_time_seconds(&tmp),
isc_time_nanoseconds(&tmp));
}
result = isc_timer_reset(zone->timer, isc_timertype_once, &next,
NULL, true);
result = isc_timer_reset(zone->timer, isc_timertype_once, NULL,
&interval, true);
if (result != ISC_R_SUCCESS) {
dns_zone_log(zone, ISC_LOG_ERROR,
"could not reset zone timer: %s",

View file

@ -92,7 +92,7 @@ struct isc_timermgr {
isc_heap_t *heap;
};
static inline isc_result_t
static isc_result_t
schedule(isc_timer_t *timer, isc_time_t *now, bool signal_ok) {
isc_timermgr_t *manager;
isc_time_t due;
@ -170,7 +170,7 @@ schedule(isc_timer_t *timer, isc_time_t *now, bool signal_ok) {
return (ISC_R_SUCCESS);
}
static inline void
static void
deschedule(isc_timer_t *timer) {
isc_timermgr_t *manager;