quota.h revision 153816
117683Spst/*
239291Sfenner * Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
317683Spst * Copyright (C) 2000, 2001  Internet Software Consortium.
417683Spst *
517683Spst * Permission to use, copy, modify, and distribute this software for any
617683Spst * purpose with or without fee is hereby granted, provided that the above
717683Spst * copyright notice and this permission notice appear in all copies.
817683Spst *
917683Spst * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
1017683Spst * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1117683Spst * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
1217683Spst * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1317683Spst * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
1417683Spst * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1517683Spst * PERFORMANCE OF THIS SOFTWARE.
1617683Spst */
1717683Spst
1817683Spst/* $Id: quota.h,v 1.8.12.6 2005/08/11 15:00:08 marka Exp $ */
1917683Spst
2017683Spst#ifndef ISC_QUOTA_H
2117683Spst#define ISC_QUOTA_H 1
2217683Spst
2317683Spst/*****
2417683Spst ***** Module Info
2517683Spst *****/
2617683Spst
2717683Spst/*
2817683Spst * Quota
2917683Spst *
3017683Spst * The isc_quota_t object is a simple helper object for implementing
3117683Spst * quotas on things like the number of simultaneous connections to
3217683Spst * a server.  It keeps track of the amount of quota in use, and
3317683Spst * encapsulates the locking necessary to allow multiple tasks to
3417683Spst * share a quota.
35127664Sbms */
36214518Srpaulo
3717683Spst/***
3817683Spst *** Imports.
3975107Sfenner ***/
4075107Sfenner
4175107Sfenner#include <isc/lang.h>
4275107Sfenner#include <isc/mutex.h>
43127664Sbms#include <isc/types.h>
44127664Sbms
45127664Sbms/*****
46214518Srpaulo ***** Types.
47214518Srpaulo *****/
48214518Srpaulo
49214518SrpauloISC_LANG_BEGINDECLS
50214518Srpaulo
51214518Srpaulostruct isc_quota {
52214518Srpaulo	isc_mutex_t	lock;
53214518Srpaulo	/* Locked by lock. */
5417683Spst	int 		max;
55183102Scsjp	int 		used;
56127664Sbms	int		soft;
5717683Spst};
5817683Spst
5917683Spstisc_result_t
6017683Spstisc_quota_init(isc_quota_t *quota, int max);
61235426Sdelphij/*
6217683Spst * Initialize a quota object.
63127664Sbms *
6498530Sfenner * Returns:
6598530Sfenner * 	ISC_R_SUCCESS
6617683Spst *	Other error	Lock creation failed.
6717683Spst */
6817683Spst
6917683Spstvoid
7017683Spstisc_quota_destroy(isc_quota_t *quota);
71146768Ssam/*
72146768Ssam * Destroy a quota object.
73146768Ssam */
74146768Ssam
7517683Spstvoid
7617683Spstisc_quota_soft(isc_quota_t *quota, int soft);
77127664Sbms/*
78127664Sbms * Turn on/off soft quotas.
79127664Sbms */
80127664Sbms
81127664Sbmsvoid
82190225Srpauloisc_quota_max(isc_quota_t *quota, int max);
83190225Srpaulo/*
84190225Srpaulo * Re-set a maximum quota.
85190225Srpaulo */
86235426Sdelphij
87190225Srpauloisc_result_t
88190225Srpauloisc_quota_reserve(isc_quota_t *quota);
89190225Srpaulo/*
90190225Srpaulo * Attempt to reserve one unit of 'quota'.
91190225Srpaulo *
92190225Srpaulo * Returns:
9317683Spst * 	ISC_R_SUCCESS	Success
94190225Srpaulo *	ISC_R_SOFTQUOTA	Success soft quota reached
95190225Srpaulo *	ISC_R_QUOTA	Quota is full
96190225Srpaulo */
97190225Srpaulo
98190225Srpaulovoid
99190225Srpauloisc_quota_release(isc_quota_t *quota);
100190225Srpaulo/*
101190225Srpaulo * Release one unit of quota.
102190225Srpaulo */
103190225Srpaulo
104190225Srpauloisc_result_t
105190225Srpauloisc_quota_attach(isc_quota_t *quota, isc_quota_t **p);
106190225Srpaulo/*
107190225Srpaulo * Like isc_quota_reserve, and also attaches '*p' to the
108214518Srpaulo * quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA).
109235426Sdelphij */
110235426Sdelphij
111235426Sdelphijvoid
112235426Sdelphijisc_quota_detach(isc_quota_t **p);
113235426Sdelphij/*
114235426Sdelphij * Like isc_quota_release, and also detaches '*p' from the
115235426Sdelphij * quota.
116235426Sdelphij */
117235426Sdelphij
118235426SdelphijISC_LANG_ENDDECLS
119235426Sdelphij
120235426Sdelphij#endif /* ISC_QUOTA_H */
121235426Sdelphij