From 85f0f10eeb2aee157fe99731375d7aadc2857def Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Mon, 6 Sep 1999 04:41:38 +0000 Subject: [PATCH] add bufferlist.c and bufferlist.h --- lib/isc/Makefile.in | 4 +- lib/isc/bufferlist.c | 59 ++++++++++++++++++++ lib/isc/include/isc/Makefile.in | 3 +- lib/isc/include/isc/bufferlist.h | 95 ++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 lib/isc/bufferlist.c create mode 100644 lib/isc/include/isc/bufferlist.h diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index e4f5e46115..098eb277c9 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -37,14 +37,14 @@ NLSOBJS = nls/msgcat.@O@ PTHREADOBJS = pthreads/condition.@O@ OBJS = @ISC_EXTRA_OBJS@ \ - assertions.@O@ base64.@O@ buffer.@O@ error.@O@ \ + assertions.@O@ base64.@O@ buffer.@O@ bufferlist.@O@ error.@O@ \ heap.@O@ lex.@O@ lib.@O@ mem.@O@ result.@O@ \ rwlock.@O@ serial.@O@ sockaddr.@O@ symtab.@O@ str.@O@ event.@O@ \ task.@O@ timer.@O@ version.@O@ \ ${UNIXOBJS} ${NLSOBJS} ${PTHREADOBJS} SRCS = @ISC_EXTRA_SRCS@ \ - assertions.c base64.c buffer.c error.c \ + assertions.c base64.c buffer.c bufferlist.c error.c \ heap.c lex.c lib.c mem.c result.c \ rwlock.c sockaddr.c symtab.c str.c event.c \ task.c timer.c version.c diff --git a/lib/isc/bufferlist.c b/lib/isc/bufferlist.c new file mode 100644 index 0000000000..f64a9ecb48 --- /dev/null +++ b/lib/isc/bufferlist.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 1999 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 + +#include +#include +#include +#include + +unsigned int +isc_bufferlist_usedcount(isc_bufferlist_t *bl) +{ + isc_buffer_t *buffer; + unsigned int length; + + REQUIRE(bl != NULL); + + length = 0; + buffer = ISC_LIST_HEAD(*bl); + while (buffer != NULL) { + length += isc_buffer_usedcount(buffer); + buffer = ISC_LIST_NEXT(buffer, link); + } + + return (length); +} + +unsigned int +isc_bufferlist_availablecount(isc_bufferlist_t *bl) +{ + isc_buffer_t *buffer; + unsigned int length; + + REQUIRE(bl != NULL); + + length = 0; + buffer = ISC_LIST_HEAD(*bl); + while (buffer != NULL) { + length += isc_buffer_availablecount(buffer); + buffer = ISC_LIST_NEXT(buffer, link); + } + + return (length); +} diff --git a/lib/isc/include/isc/Makefile.in b/lib/isc/include/isc/Makefile.in index 13e1c0389d..58d18d020b 100644 --- a/lib/isc/include/isc/Makefile.in +++ b/lib/isc/include/isc/Makefile.in @@ -19,7 +19,8 @@ top_srcdir = @top_srcdir@ @BIND9_VERSION@ -HEADERS = assertions.h base64.h boolean.h buffer.h error.h event.h \ +HEADERS = assertions.h base64.h boolean.h buffer.h bufferlist.h \ + error.h event.h \ eventclass.h heap.h int.h interfaceiter.h lang.h lex.h lib.h \ list.h mem.h msgcat.h netaddr.h rbtgen.h region.h result.h \ resultclass.h rwlock.h serial.h sockaddr.h socket.h str.h \ diff --git a/lib/isc/include/isc/bufferlist.h b/lib/isc/include/isc/bufferlist.h new file mode 100644 index 0000000000..a2674ec1bb --- /dev/null +++ b/lib/isc/include/isc/bufferlist.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 1998, 1999 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_BUFFERLIST_H +#define ISC_BUFFERLIST_H 1 + +/***** + ***** Module Info + *****/ + +/* + * Buffer Lists + * + * Buffer lists have no synchronization. Clients must ensure exclusive + * access. + * + * Reliability: + * No anticipated impact. + + * Security: + * No anticipated impact. + * + * Standards: + * None. + */ + +/*** + *** Imports + ***/ + +#include +#include +#include +#include +#include +#include +#include + +ISC_LANG_BEGINDECLS + +/*** + *** Types + ***/ + +typedef ISC_LIST(isc_buffer_t) isc_bufferlist_t; + +/*** + *** Functions + ***/ + +unsigned int +isc_bufferlist_usedcount(isc_bufferlist_t *bl); +/* + * Return the length of the sum of all used regions of all buffers in + * the buffer list 'bl' + * + * Requires: + * + * 'bl' is not NULL. + * + * Returns: + * sum of all used regions' lengths. + */ + +unsigned int +isc_bufferlist_availablecount(isc_bufferlist_t *bl); +/* + * Return the length of the sum of all available regions of all buffers in + * the buffer list 'bl' + * + * Requires: + * + * 'bl' is not NULL. + * + * Returns: + * sum of all available regions' lengths. + */ + +ISC_LANG_ENDDECLS + +#endif /* ISC_BUFFERLIST_H */