Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
BIND
Commits
5f2d1b96
Commit
5f2d1b96
authored
Jan 11, 2000
by
Andreas Gustafsson
Browse files
new type isc_quota_t, for client (and other) quotas
parent
c5f15d21
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/isc/Makefile.in
View file @
5f2d1b96
...
...
@@ -47,7 +47,7 @@ OBJS = @ISC_EXTRA_OBJS@ \
assertions.@O@ base64.@O@ bitstring.@O@ buffer.@O@
\
bufferlist.@O@ commandline.@O@ error.@O@ event.@O@ heap.@O@
\
lex.@O@ lfsr.@O@ lib.@O@ log.@O@
\
mem.@O@ mutexblock.@O@ random.@O@
\
mem.@O@ mutexblock.@O@
quota.@O@
random.@O@
\
ratelimiter.@O@ result.@O@ rwlock.@O@
\
serial.@O@ sockaddr.@O@ str.@O@ symtab.@O@
\
task.@O@ taskpool.@O@ timer.@O@ version.@O@
\
...
...
@@ -58,7 +58,7 @@ SRCS = @ISC_EXTRA_SRCS@ \
assertions.c base64.c bitstring.c buffer.c
\
bufferlist.c commandline.c error.c event.c heap.c
\
lex.c lfsr.c lib.c log.c
\
mem.c mutexblock.c random.c
\
mem.c mutexblock.c
quota.c
random.c
\
ratelimiter.c result.c rwlock.c
\
serial.c sockaddr.c str.c symtab.c
\
task.c taskpool.c timer.c version.c
...
...
lib/isc/include/isc/quota.h
0 → 100644
View file @
5f2d1b96
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM 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.
*/
#ifndef ISC_QUOTA_H
#define ISC_QUOTA_H 1
/*****
***** Module Info
*****/
/*
* Quota
*
* The isc_quota_t object is a simple helper object for implementing
* quotas on things like the number of simultaneous connections to
* a server. It keeps track of the amount of quota in use, and
* encapsulates the locking necessary to allow multiple tasks to
* share a quota.
*/
/***
*** Imports.
***/
#include
<isc/mutex.h>
#include
<isc/result.h>
/*****
***** Types.
*****/
ISC_LANG_BEGINDECLS
typedef
struct
isc_quota
isc_quota_t
;
struct
isc_quota
{
isc_mutex_t
lock
;
/* Locked by lock. */
int
max
;
int
used
;
};
isc_result_t
isc_quota_init
(
isc_quota_t
*
quota
,
int
max
);
/*
* Initialize a quota object.
*
* Returns:
* ISC_R_SUCCESS
* Other error Lock creation failed.
*/
void
isc_quota_destroy
(
isc_quota_t
*
quota
);
/*
* Destroy a quota object.
*/
isc_result_t
isc_quota_reserve
(
isc_quota_t
*
quota
);
/*
* Attempt to reserve one unit of 'quota'.
*
* Returns:
* ISC_R_SUCCESS Success
* ISC_R_QUOTA Quota is full
*/
void
isc_quota_release
(
isc_quota_t
*
quota
);
/*
* Release one unit of quota.
*/
ISC_LANG_ENDDECLS
#endif
/* ISC_QUOTA_H */
lib/isc/quota.c
0 → 100644
View file @
5f2d1b96
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM 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.
*/
#include
<isc/assertions.h>
#include
<isc/quota.h>
#include
<isc/util.h>
isc_result_t
isc_quota_init
(
isc_quota_t
*
quota
,
int
max
)
{
quota
->
max
=
max
;
quota
->
used
=
0
;
return
(
isc_mutex_init
(
&
quota
->
lock
));
}
void
isc_quota_destroy
(
isc_quota_t
*
quota
)
{
quota
->
max
=
-
1
;
quota
->
used
=
-
1
;
RUNTIME_CHECK
(
isc_mutex_destroy
(
&
quota
->
lock
)
==
ISC_R_SUCCESS
);
}
isc_result_t
isc_quota_reserve
(
isc_quota_t
*
quota
)
{
isc_result_t
result
;
LOCK
(
&
quota
->
lock
);
if
(
quota
->
used
<
quota
->
max
)
{
quota
->
used
++
;
result
=
ISC_R_SUCCESS
;
}
else
{
result
=
ISC_R_QUOTA
;
}
UNLOCK
(
&
quota
->
lock
);
return
(
result
);
}
void
isc_quota_release
(
isc_quota_t
*
quota
)
{
LOCK
(
&
quota
->
lock
);
INSIST
(
quota
->
used
>
0
);
quota
->
used
--
;
UNLOCK
(
&
quota
->
lock
);
}
util/copyrights
View file @
5f2d1b96
...
...
@@ -567,6 +567,7 @@
./lib/isc/include/isc/netaddr.h C 1998,1999
./lib/isc/include/isc/platform.h.in C 1999
./lib/isc/include/isc/print.h C 1999
./lib/isc/include/isc/quota.h C 2000
./lib/isc/include/isc/random.h C 1999
./lib/isc/include/isc/ratelimiter.h C 1999
./lib/isc/include/isc/rbtgen.h C 1998,1999
...
...
@@ -607,6 +608,7 @@
./lib/isc/pthreads/include/isc/mutex.h C 1998,1999
./lib/isc/pthreads/include/isc/once.h C 1999
./lib/isc/pthreads/include/isc/thread.h C 1998,1999
./lib/isc/quota.c C 2000
./lib/isc/random.c C 1999
./lib/isc/ratelimiter.c C 1999
./lib/isc/rbtgen.c C 1998,1999
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment