ratelimiter.c revision 499b34cea04a46823d003d4c0520c8b03e8513cb
/*
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: ratelimiter.c,v 1.18 2001/01/09 21:56:23 bwelling Exp $ */
#include <config.h>
#include <isc/ratelimiter.h>
typedef enum {
struct isc_ratelimiter {
int refs;
isc_task_t * task;
isc_timer_t * timer;
};
static void
static void
{
return ISC_R_NOMEMORY;
if (result != ISC_R_SUCCESS)
goto free_mem;
if (result != ISC_R_SUCCESS)
goto free_mutex;
/*
* Increment the reference count to indicate that we may
* (soon) have events outstanding.
*/
sizeof(isc_event_t),
*ratelimiterp = rl;
return (ISC_R_SUCCESS);
return (result);
}
/*
* If the timer is currently running, change its rate.
*/
}
return (result);
}
void
if (pertic == 0)
pertic = 1;
}
{
if (result == ISC_R_SUCCESS) {
}
} else {
}
return (result);
}
static void
isc_event_t *p;
while (pertic != 0) {
pertic--;
if (p != NULL) {
/*
* There is work to do. Let's do it after unlocking.
*/
} else {
/*
* No work left to do. Stop the timer so that we don't
* waste resources by having it fire periodically.
*/
pertic = 0; /* Force the loop to exit. */
}
if (p != NULL) {
isc_task_send(evtask, &p);
}
}
}
void
}
/*
* Send an event to our task. The delivery of this event
* indicates that no more timer events will be delivered.
*/
}
static void
}
static void
}
void
}
void
if (free_now)
}