00001 /* 00002 * Copyright (C) 2004-2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC") 00003 * Copyright (C) 1999-2002 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: ratelimiter.h,v 1.23 2009/01/18 23:48:14 tbox Exp $ */ 00019 00020 #ifndef ISC_RATELIMITER_H 00021 #define ISC_RATELIMITER_H 1 00022 00023 /***** 00024 ***** Module Info 00025 *****/ 00026 00027 /*! \file isc/ratelimiter.h 00028 * \brief A rate limiter is a mechanism for dispatching events at a limited 00029 * rate. This is intended to be used when sending zone maintenance 00030 * SOA queries, NOTIFY messages, etc. 00031 */ 00032 00033 /*** 00034 *** Imports. 00035 ***/ 00036 00037 #include <isc/lang.h> 00038 #include <isc/types.h> 00039 00040 ISC_LANG_BEGINDECLS 00041 00042 /***** 00043 ***** Functions. 00044 *****/ 00045 00046 isc_result_t 00047 isc_ratelimiter_create(isc_mem_t *mctx, isc_timermgr_t *timermgr, 00048 isc_task_t *task, isc_ratelimiter_t **ratelimiterp); 00049 /*%< 00050 * Create a rate limiter. The execution interval is initially undefined. 00051 */ 00052 00053 isc_result_t 00054 isc_ratelimiter_setinterval(isc_ratelimiter_t *rl, isc_interval_t *interval); 00055 /*!< 00056 * Set the minimum interval between event executions. 00057 * The interval value is copied, so the caller need not preserve it. 00058 * 00059 * Requires: 00060 * '*interval' is a nonzero interval. 00061 */ 00062 00063 void 00064 isc_ratelimiter_setpertic(isc_ratelimiter_t *rl, isc_uint32_t perint); 00065 /*%< 00066 * Set the number of events processed per interval timer tick. 00067 * If 'perint' is zero it is treated as 1. 00068 */ 00069 00070 isc_result_t 00071 isc_ratelimiter_enqueue(isc_ratelimiter_t *rl, isc_task_t *task, 00072 isc_event_t **eventp); 00073 /*%< 00074 * Queue an event for rate-limited execution. 00075 * 00076 * This is similar 00077 * to doing an isc_task_send() to the 'task', except that the 00078 * execution may be delayed to achieve the desired rate of 00079 * execution. 00080 * 00081 * '(*eventp)->ev_sender' is used to hold the task. The caller 00082 * must ensure that the task exists until the event is delivered. 00083 * 00084 * Requires: 00085 *\li An interval has been set by calling 00086 * isc_ratelimiter_setinterval(). 00087 * 00088 *\li 'task' to be non NULL. 00089 *\li '(*eventp)->ev_sender' to be NULL. 00090 */ 00091 00092 isc_result_t 00093 isc_ratelimiter_dequeue(isc_ratelimiter_t *rl, isc_event_t *event); 00094 /* 00095 * Dequeue a event off the ratelimiter queue. 00096 * 00097 * Returns: 00098 * \li ISC_R_NOTFOUND if the event is no longer linked to the rate limiter. 00099 * \li ISC_R_SUCCESS 00100 */ 00101 00102 void 00103 isc_ratelimiter_shutdown(isc_ratelimiter_t *ratelimiter); 00104 /*%< 00105 * Shut down a rate limiter. 00106 * 00107 * Ensures: 00108 *\li All events that have not yet been 00109 * dispatched to the task are dispatched immediately with 00110 * the #ISC_EVENTATTR_CANCELED bit set in ev_attributes. 00111 * 00112 *\li Further attempts to enqueue events will fail with 00113 * #ISC_R_SHUTTINGDOWN. 00114 * 00115 *\li The rate limiter is no longer attached to its task. 00116 */ 00117 00118 void 00119 isc_ratelimiter_attach(isc_ratelimiter_t *source, isc_ratelimiter_t **target); 00120 /*%< 00121 * Attach to a rate limiter. 00122 */ 00123 00124 void 00125 isc_ratelimiter_detach(isc_ratelimiter_t **ratelimiterp); 00126 /*%< 00127 * Detach from a rate limiter. 00128 */ 00129 00130 isc_result_t 00131 isc_ratelimiter_stall(isc_ratelimiter_t *rl); 00132 /*%< 00133 * Stall event processing. 00134 */ 00135 00136 isc_result_t 00137 isc_ratelimiter_release(isc_ratelimiter_t *rl); 00138 /*%< 00139 * Release a stalled rate limiter. 00140 */ 00141 00142 ISC_LANG_ENDDECLS 00143 00144 #endif /* ISC_RATELIMITER_H */