d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2016 Internet Systems Consortium, Inc. ("ISC")
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson */
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: timer.c,v 1.7 2007/06/19 23:47:16 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson#include <config.h>
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson#include <isc/result.h>
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson#include <isc/time.h>
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson#include <isc/timer.h>
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson#include <dns/types.h>
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson#include <dns/timer.h>
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson#define CHECK(op) \
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson do { result = (op); \
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson if (result != ISC_R_SUCCESS) goto failure; \
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson } while (0)
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafssonisc_result_t
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafssondns_timer_setidle(isc_timer_t *timer, unsigned int maxtime,
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson unsigned int idletime, isc_boolean_t purge)
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson{
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson isc_result_t result;
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson isc_interval_t maxinterval, idleinterval;
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson isc_time_t expires;
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson /* Compute the time of expiry. */
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson isc_interval_set(&maxinterval, maxtime, 0);
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson CHECK(isc_time_nowplusinterval(&expires, &maxinterval));
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson /*
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson * Compute the idle interval, and add a spare nanosecond to
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson * work around the silly limitation of the ISC timer interface
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson * that you cannot specify an idle interval of zero.
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson */
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson isc_interval_set(&idleinterval, idletime, 1);
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson CHECK(isc_timer_reset(timer, isc_timertype_once,
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson &expires, &idleinterval,
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson purge));
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson failure:
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson return (result);
d8f90196479e065286428dd8cbd1615d0f105f8cAndreas Gustafsson}