1135446Strhodes/* 2193149Sdougb * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 3135446Strhodes * Copyright (C) 2000, 2001 Internet Software Consortium. 4135446Strhodes * 5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any 6135446Strhodes * purpose with or without fee is hereby granted, provided that the above 7135446Strhodes * copyright notice and this permission notice appear in all copies. 8135446Strhodes * 9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11135446Strhodes * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15135446Strhodes * PERFORMANCE OF THIS SOFTWARE. 16135446Strhodes */ 17135446Strhodes 18234010Sdougb/* $Id: quota.h,v 1.16 2007/06/19 23:47:18 tbox Exp $ */ 19135446Strhodes 20135446Strhodes#ifndef ISC_QUOTA_H 21135446Strhodes#define ISC_QUOTA_H 1 22135446Strhodes 23135446Strhodes/***** 24135446Strhodes ***** Module Info 25135446Strhodes *****/ 26135446Strhodes 27170222Sdougb/*! \file isc/quota.h 28135446Strhodes * 29170222Sdougb * \brief The isc_quota_t object is a simple helper object for implementing 30135446Strhodes * quotas on things like the number of simultaneous connections to 31135446Strhodes * a server. It keeps track of the amount of quota in use, and 32135446Strhodes * encapsulates the locking necessary to allow multiple tasks to 33135446Strhodes * share a quota. 34135446Strhodes */ 35135446Strhodes 36135446Strhodes/*** 37135446Strhodes *** Imports. 38135446Strhodes ***/ 39135446Strhodes 40135446Strhodes#include <isc/lang.h> 41135446Strhodes#include <isc/mutex.h> 42135446Strhodes#include <isc/types.h> 43135446Strhodes 44135446Strhodes/***** 45135446Strhodes ***** Types. 46135446Strhodes *****/ 47135446Strhodes 48135446StrhodesISC_LANG_BEGINDECLS 49135446Strhodes 50170222Sdougb/*% isc_quota structure */ 51135446Strhodesstruct isc_quota { 52170222Sdougb isc_mutex_t lock; /*%< Locked by lock. */ 53135446Strhodes int max; 54135446Strhodes int used; 55153816Sdougb int soft; 56135446Strhodes}; 57135446Strhodes 58135446Strhodesisc_result_t 59135446Strhodesisc_quota_init(isc_quota_t *quota, int max); 60170222Sdougb/*%< 61135446Strhodes * Initialize a quota object. 62135446Strhodes * 63135446Strhodes * Returns: 64135446Strhodes * ISC_R_SUCCESS 65135446Strhodes * Other error Lock creation failed. 66135446Strhodes */ 67135446Strhodes 68135446Strhodesvoid 69135446Strhodesisc_quota_destroy(isc_quota_t *quota); 70170222Sdougb/*%< 71135446Strhodes * Destroy a quota object. 72135446Strhodes */ 73135446Strhodes 74135446Strhodesvoid 75153816Sdougbisc_quota_soft(isc_quota_t *quota, int soft); 76170222Sdougb/*%< 77170222Sdougb * Set a soft quota. 78135446Strhodes */ 79135446Strhodes 80153816Sdougbvoid 81153816Sdougbisc_quota_max(isc_quota_t *quota, int max); 82170222Sdougb/*%< 83153816Sdougb * Re-set a maximum quota. 84153816Sdougb */ 85153816Sdougb 86135446Strhodesisc_result_t 87135446Strhodesisc_quota_reserve(isc_quota_t *quota); 88170222Sdougb/*%< 89135446Strhodes * Attempt to reserve one unit of 'quota'. 90135446Strhodes * 91135446Strhodes * Returns: 92170222Sdougb * \li #ISC_R_SUCCESS Success 93170222Sdougb * \li #ISC_R_SOFTQUOTA Success soft quota reached 94170222Sdougb * \li #ISC_R_QUOTA Quota is full 95135446Strhodes */ 96135446Strhodes 97135446Strhodesvoid 98135446Strhodesisc_quota_release(isc_quota_t *quota); 99170222Sdougb/*%< 100135446Strhodes * Release one unit of quota. 101135446Strhodes */ 102135446Strhodes 103135446Strhodesisc_result_t 104135446Strhodesisc_quota_attach(isc_quota_t *quota, isc_quota_t **p); 105170222Sdougb/*%< 106135446Strhodes * Like isc_quota_reserve, and also attaches '*p' to the 107135446Strhodes * quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA). 108135446Strhodes */ 109135446Strhodes 110135446Strhodesvoid 111135446Strhodesisc_quota_detach(isc_quota_t **p); 112170222Sdougb/*%< 113135446Strhodes * Like isc_quota_release, and also detaches '*p' from the 114135446Strhodes * quota. 115135446Strhodes */ 116135446Strhodes 117135446StrhodesISC_LANG_ENDDECLS 118135446Strhodes 119135446Strhodes#endif /* ISC_QUOTA_H */ 120