5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: quota.h,v 1.16 2007/06/19 23:47:18 tbox Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson#ifndef ISC_QUOTA_H
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson#define ISC_QUOTA_H 1
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson/*****
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson ***** Module Info
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson *****/
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file isc/quota.h
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \brief The isc_quota_t object is a simple helper object for implementing
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * quotas on things like the number of simultaneous connections to
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * a server. It keeps track of the amount of quota in use, and
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * encapsulates the locking necessary to allow multiple tasks to
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * share a quota.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson/***
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson *** Imports.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson ***/
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
904463e94cafd59c8284f472ea8f58f1f311b8cbDavid Lawrence#include <isc/lang.h>
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson#include <isc/mutex.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/types.h>
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson/*****
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson ***** Types.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson *****/
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas GustafssonISC_LANG_BEGINDECLS
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*% isc_quota structure */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonstruct isc_quota {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_mutex_t lock; /*%< Locked by lock. */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson int max;
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson int used;
c9b4dafc92c820c397ee2a3d5dafa46acb7cde58Mark Andrews int soft;
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson};
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonisc_result_t
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonisc_quota_init(isc_quota_t *quota, int max);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Initialize a quota object.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson *
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * Returns:
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * ISC_R_SUCCESS
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * Other error Lock creation failed.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonvoid
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonisc_quota_destroy(isc_quota_t *quota);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * Destroy a quota object.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
1255d388f034dc556d235a002527101781dbeb29Mark Andrewsvoid
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrewsisc_quota_soft(isc_quota_t *quota, int soft);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews * Set a soft quota.
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews */
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrewsvoid
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrewsisc_quota_max(isc_quota_t *quota, int max);
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews/*%<
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews * Re-set a maximum quota.
1255d388f034dc556d235a002527101781dbeb29Mark Andrews */
1255d388f034dc556d235a002527101781dbeb29Mark Andrews
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonisc_result_t
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonisc_quota_reserve(isc_quota_t *quota);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * Attempt to reserve one unit of 'quota'.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson *
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * Returns:
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews * \li #ISC_R_SUCCESS Success
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews * \li #ISC_R_SOFTQUOTA Success soft quota reached
8abe06b25d245ab2955d81525bfe6bd29b80908eMark Andrews * \li #ISC_R_QUOTA Quota is full
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonvoid
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafssonisc_quota_release(isc_quota_t *quota);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson * Release one unit of quota.
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson */
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafssonisc_result_t
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafssonisc_quota_attach(isc_quota_t *quota, isc_quota_t **p);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafsson * Like isc_quota_reserve, and also attaches '*p' to the
1255d388f034dc556d235a002527101781dbeb29Mark Andrews * quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA).
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafsson */
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafsson
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafssonvoid
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafssonisc_quota_detach(isc_quota_t **p);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafsson * Like isc_quota_release, and also detaches '*p' from the
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafsson * quota.
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafsson */
8c36d7eeb9e71676a6fa78fb5b51bf123c8cc614Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas GustafssonISC_LANG_ENDDECLS
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson
5f2d1b96ac4bc3870423792520030a5ecabda925Andreas Gustafsson#endif /* ISC_QUOTA_H */