From: Mark Andrews Date: Fri, 26 Jul 2002 06:42:02 +0000 (+0000) Subject: 1341. [func] Allow a rate limiter to be stalled. X-Git-Tag: v9.2.3rc1~104^2~451 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=012a2b979e011b13ba0d291c279dc65a167c039e;p=thirdparty%2Fbind9.git 1341. [func] Allow a rate limiter to be stalled. --- diff --git a/CHANGES b/CHANGES index 7857541c147..70dbf119daf 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +1341. [func] Allow a rate limiter to be stalled. + 1340. [bug] Delay and spread out the startup refresh load. 1339. [func] dig, host and nslookup now use IP6.ARPA for nibble diff --git a/lib/isc/include/isc/ratelimiter.h b/lib/isc/include/isc/ratelimiter.h index f2f93329efe..411b8838eba 100644 --- a/lib/isc/include/isc/ratelimiter.h +++ b/lib/isc/include/isc/ratelimiter.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: ratelimiter.h,v 1.13 2001/01/09 21:57:24 bwelling Exp $ */ +/* $Id: ratelimiter.h,v 1.14 2002/07/26 06:42:01 marka Exp $ */ #ifndef ISC_RATELIMITER_H #define ISC_RATELIMITER_H 1 @@ -115,6 +115,18 @@ isc_ratelimiter_detach(isc_ratelimiter_t **ratelimiterp); * Detach from a rate limiter. */ +isc_result_t +isc_ratelimiter_stall(isc_ratelimiter_t *rl); +/* + * Stall event processing. + */ + +isc_result_t +isc_ratelimiter_release(isc_ratelimiter_t *rl); +/* + * Release a stalled rate limiter. + */ + ISC_LANG_ENDDECLS #endif /* ISC_RATELIMITER_H */ diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index e6921539d3f..9f7f654b2bc 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: ratelimiter.c,v 1.18 2001/01/09 21:56:23 bwelling Exp $ */ +/* $Id: ratelimiter.c,v 1.19 2002/07/26 06:42:01 marka Exp $ */ #include @@ -27,6 +27,7 @@ #include typedef enum { + isc_ratelimiter_stalled, isc_ratelimiter_ratelimited, isc_ratelimiter_worklimited, isc_ratelimiter_shuttingdown @@ -139,7 +140,8 @@ isc_ratelimiter_enqueue(isc_ratelimiter_t *rl, isc_task_t *task, REQUIRE(ev->ev_sender == NULL); LOCK(&rl->lock); - if (rl->state == isc_ratelimiter_ratelimited) { + if (rl->state == isc_ratelimiter_ratelimited || + rl->state == isc_ratelimiter_stalled) { isc_event_t *ev = *eventp; ev->ev_sender = task; ISC_LIST_APPEND(rl->pending, ev, ev_link); @@ -274,3 +276,51 @@ isc_ratelimiter_detach(isc_ratelimiter_t **rlp) { *rlp = NULL; } +isc_result_t +isc_ratelimiter_stall(isc_ratelimiter_t *rl) { + isc_result_t result = ISC_R_SUCCESS; + + LOCK(&rl->lock); + switch (rl->state) { + case isc_ratelimiter_shuttingdown: + result = ISC_R_SHUTTINGDOWN; + break; + case isc_ratelimiter_ratelimited: + result = isc_timer_reset(rl->timer, isc_timertype_inactive, + NULL, NULL, ISC_FALSE); + RUNTIME_CHECK(result == ISC_R_SUCCESS); + case isc_ratelimiter_worklimited: + case isc_ratelimiter_stalled: + rl->state = isc_ratelimiter_stalled; + break; + } + UNLOCK(&rl->lock); + return (result); +} + +isc_result_t +isc_ratelimiter_release(isc_ratelimiter_t *rl) { + isc_result_t result = ISC_R_SUCCESS; + + LOCK(&rl->lock); + switch (rl->state) { + case isc_ratelimiter_shuttingdown: + result = ISC_R_SHUTTINGDOWN; + break; + case isc_ratelimiter_stalled: + if (!ISC_LIST_EMPTY(rl->pending)) { + result = isc_timer_reset(rl->timer, + isc_timertype_ticker, NULL, + &rl->interval, ISC_FALSE); + if (result == ISC_R_SUCCESS) + rl->state = isc_ratelimiter_ratelimited; + } else + rl->state = isc_ratelimiter_worklimited; + break; + case isc_ratelimiter_ratelimited: + case isc_ratelimiter_worklimited: + break; + } + UNLOCK(&rl->lock); + return (result); +}