1067. [func] Allow quotas to be soft, isc_quota_soft().
This commit is contained in:
2
CHANGES
2
CHANGES
@@ -1,3 +1,5 @@
|
||||
1067. [func] Allow quotas to be soft, isc_quota_soft().
|
||||
|
||||
1066. [bug] Provide a thread safe wrapper for strerror().
|
||||
[RT #1689]
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: quota.h,v 1.8 2001/01/09 21:57:22 bwelling Exp $ */
|
||||
/* $Id: quota.h,v 1.9 2001/10/22 07:09:25 marka Exp $ */
|
||||
|
||||
#ifndef ISC_QUOTA_H
|
||||
#define ISC_QUOTA_H 1
|
||||
@@ -53,6 +53,7 @@ struct isc_quota {
|
||||
/* Locked by lock. */
|
||||
int max;
|
||||
int used;
|
||||
isc_boolean_t soft;
|
||||
};
|
||||
|
||||
isc_result_t
|
||||
@@ -71,6 +72,12 @@ isc_quota_destroy(isc_quota_t *quota);
|
||||
* Destroy a quota object.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_quota_soft(isc_quota_t *quota, isc_boolean_t soft);
|
||||
/*
|
||||
* Turn on/off soft quotas.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_quota_reserve(isc_quota_t *quota);
|
||||
/*
|
||||
@@ -78,6 +85,7 @@ isc_quota_reserve(isc_quota_t *quota);
|
||||
*
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS Success
|
||||
* ISC_R_SOFTQUOTA Success soft quota reached
|
||||
* ISC_R_QUOTA Quota is full
|
||||
*/
|
||||
|
||||
@@ -91,7 +99,7 @@ isc_result_t
|
||||
isc_quota_attach(isc_quota_t *quota, isc_quota_t **p);
|
||||
/*
|
||||
* Like isc_quota_reserve, and also attaches '*p' to the
|
||||
* quota if successful.
|
||||
* quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA).
|
||||
*/
|
||||
|
||||
void
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: result.h,v 1.57 2001/06/15 22:07:51 gson Exp $ */
|
||||
/* $Id: result.h,v 1.58 2001/10/22 07:09:24 marka Exp $ */
|
||||
|
||||
#ifndef ISC_RESULT_H
|
||||
#define ISC_RESULT_H 1
|
||||
@@ -78,11 +78,12 @@
|
||||
#define ISC_R_UNBALANCEDQUOTES 52 /* unbalanced quotes */
|
||||
#define ISC_R_INPROGRESS 53 /* operation in progress */
|
||||
#define ISC_R_CONNECTIONRESET 54 /* connection reset */
|
||||
#define ISC_R_SOFTQUOTA 55 /* soft quota reached */
|
||||
|
||||
/*
|
||||
* Not a result code: the number of results.
|
||||
*/
|
||||
#define ISC_R_NRESULTS 55
|
||||
#define ISC_R_NRESULTS 56
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: quota.c,v 1.11 2001/01/09 21:56:21 bwelling Exp $ */
|
||||
/* $Id: quota.c,v 1.12 2001/10/22 07:09:22 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -28,6 +28,7 @@ isc_result_t
|
||||
isc_quota_init(isc_quota_t *quota, int max) {
|
||||
quota->max = max;
|
||||
quota->used = 0;
|
||||
quota->soft = ISC_FALSE;
|
||||
return (isc_mutex_init("a->lock));
|
||||
}
|
||||
|
||||
@@ -36,9 +37,15 @@ isc_quota_destroy(isc_quota_t *quota) {
|
||||
INSIST(quota->used == 0);
|
||||
quota->max = -1;
|
||||
quota->used = -1;
|
||||
quota->soft = ISC_FALSE;
|
||||
DESTROYLOCK("a->lock);
|
||||
}
|
||||
|
||||
void
|
||||
isc_quota_soft(isc_quota_t *quota, isc_boolean_t soft) {
|
||||
quota->soft = soft;
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_quota_reserve(isc_quota_t *quota) {
|
||||
isc_result_t result;
|
||||
@@ -47,7 +54,11 @@ isc_quota_reserve(isc_quota_t *quota) {
|
||||
quota->used++;
|
||||
result = ISC_R_SUCCESS;
|
||||
} else {
|
||||
result = ISC_R_QUOTA;
|
||||
if (quota->soft) {
|
||||
quota->used++;
|
||||
result = ISC_R_SOFTQUOTA;
|
||||
} else
|
||||
result = ISC_R_QUOTA;
|
||||
}
|
||||
UNLOCK("a->lock);
|
||||
return (result);
|
||||
@@ -67,10 +78,9 @@ isc_quota_attach(isc_quota_t *quota, isc_quota_t **p)
|
||||
isc_result_t result;
|
||||
INSIST(p != NULL && *p == NULL);
|
||||
result = isc_quota_reserve(quota);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
*p = quota;
|
||||
return (ISC_R_SUCCESS);
|
||||
if (result == ISC_R_SUCCESS || result == ISC_R_SOFTQUOTA)
|
||||
*p = quota;
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: result.c,v 1.56 2001/06/15 22:07:50 gson Exp $ */
|
||||
/* $Id: result.c,v 1.57 2001/10/22 07:09:21 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -92,7 +92,8 @@ static const char *text[ISC_R_NRESULTS] = {
|
||||
"not blocking", /* 51 */
|
||||
"unbalanced quotes", /* 52 */
|
||||
"operation in progress", /* 53 */
|
||||
"connection reset" /* 54 */
|
||||
"connection reset", /* 54 */
|
||||
"soft quota reached" /* 55 */
|
||||
};
|
||||
|
||||
#define ISC_RESULT_RESULTSET 2
|
||||
|
||||
Reference in New Issue
Block a user