1135446Strhodes/* 2193149Sdougb * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 3135446Strhodes * Copyright (C) 2000, 2001 Internet Software Consortium. 4135446Strhodes * 5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any 6135446Strhodes * purpose with or without fee is hereby granted, provided that the above 7135446Strhodes * copyright notice and this permission notice appear in all copies. 8135446Strhodes * 9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11135446Strhodes * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15135446Strhodes * PERFORMANCE OF THIS SOFTWARE. 16135446Strhodes */ 17135446Strhodes 18234010Sdougb/* $Id: timer.c,v 1.7 2007/06/19 23:47:16 tbox Exp $ */ 19135446Strhodes 20170222Sdougb/*! \file */ 21170222Sdougb 22135446Strhodes#include <config.h> 23135446Strhodes 24135446Strhodes#include <isc/result.h> 25135446Strhodes#include <isc/time.h> 26135446Strhodes#include <isc/timer.h> 27135446Strhodes 28135446Strhodes#include <dns/types.h> 29135446Strhodes#include <dns/timer.h> 30135446Strhodes 31135446Strhodes#define CHECK(op) \ 32135446Strhodes do { result = (op); \ 33135446Strhodes if (result != ISC_R_SUCCESS) goto failure; \ 34135446Strhodes } while (0) 35135446Strhodes 36135446Strhodesisc_result_t 37135446Strhodesdns_timer_setidle(isc_timer_t *timer, unsigned int maxtime, 38135446Strhodes unsigned int idletime, isc_boolean_t purge) 39135446Strhodes{ 40135446Strhodes isc_result_t result; 41135446Strhodes isc_interval_t maxinterval, idleinterval; 42135446Strhodes isc_time_t expires; 43135446Strhodes 44135446Strhodes /* Compute the time of expiry. */ 45135446Strhodes isc_interval_set(&maxinterval, maxtime, 0); 46135446Strhodes CHECK(isc_time_nowplusinterval(&expires, &maxinterval)); 47135446Strhodes 48135446Strhodes /* 49135446Strhodes * Compute the idle interval, and add a spare nanosecond to 50135446Strhodes * work around the silly limitation of the ISC timer interface 51135446Strhodes * that you cannot specify an idle interval of zero. 52135446Strhodes */ 53135446Strhodes isc_interval_set(&idleinterval, idletime, 1); 54135446Strhodes 55135446Strhodes CHECK(isc_timer_reset(timer, isc_timertype_once, 56135446Strhodes &expires, &idleinterval, 57135446Strhodes purge)); 58135446Strhodes failure: 59135446Strhodes return (result); 60135446Strhodes} 61