timer.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: timer.c,v 1.7 2007/06/19 23:47:16 tbox Exp $ */
00019 
00020 /*! \file */
00021 
00022 #include <config.h>
00023 
00024 #include <isc/result.h>
00025 #include <isc/time.h>
00026 #include <isc/timer.h>
00027 
00028 #include <dns/types.h>
00029 #include <dns/timer.h>
00030 
00031 #define CHECK(op) \
00032         do { result = (op);                                     \
00033                 if (result != ISC_R_SUCCESS) goto failure;      \
00034         } while (0)
00035 
00036 isc_result_t
00037 dns_timer_setidle(isc_timer_t *timer, unsigned int maxtime,
00038                   unsigned int idletime, isc_boolean_t purge)
00039 {
00040         isc_result_t result;
00041         isc_interval_t maxinterval, idleinterval;
00042         isc_time_t expires;
00043 
00044         /* Compute the time of expiry. */
00045         isc_interval_set(&maxinterval, maxtime, 0);
00046         CHECK(isc_time_nowplusinterval(&expires, &maxinterval));
00047 
00048         /*
00049          * Compute the idle interval, and add a spare nanosecond to
00050          * work around the silly limitation of the ISC timer interface
00051          * that you cannot specify an idle interval of zero.
00052          */
00053         isc_interval_set(&idleinterval, idletime, 1);
00054 
00055         CHECK(isc_timer_reset(timer, isc_timertype_once,
00056                               &expires, &idleinterval,
00057                               purge));
00058  failure:
00059         return (result);
00060 }

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha