ratelimiter.c revision c110d61b173a68420d19858abb80285be0dc1120
/*
* Copyright (C) 2004, 2005, 2007, 2012, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2002 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.25 2007/06/19 23:47:17 tbox Exp $ */
/*! \file */
#include <config.h>
#include <isc/ratelimiter.h>
typedef enum {
isc_ratelimiter_idle = 2,
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);
}
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)
}
break;
/* FALLTHROUGH */
case isc_ratelimiter_idle:
case isc_ratelimiter_stalled:
break;
}
return (result);
}
break;
case isc_ratelimiter_stalled:
if (result == ISC_R_SUCCESS)
} else
break;
case isc_ratelimiter_idle:
break;
}
return (result);
}