From 07a9b8b58802575e1ec29a3c8b00e5fae1a94008 Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Fri, 10 Sep 1999 21:13:39 +0000 Subject: [PATCH] Make a few helper macros which will return lengths of regions rather than requiring an isc_region_t to fill in. Use these macros in a few places. --- lib/isc/buffer.c | 16 ---------------- lib/isc/bufferlist.c | 4 ++-- lib/isc/include/isc/buffer.h | 37 +++++++++++++++++------------------- lib/isc/unix/socket.c | 20 +++++++++---------- 4 files changed, 29 insertions(+), 48 deletions(-) diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 602a652e30..0f87b314f3 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -99,14 +99,6 @@ isc_buffer_used(isc_buffer_t *b, isc_region_t *r) { r->length = b->used; } -unsigned int -isc_buffer_usedcount(isc_buffer_t *b) -{ - REQUIRE(ISC_BUFFER_VALID(b)); - - return (b->used); -} - void isc_buffer_available(isc_buffer_t *b, isc_region_t *r) { /* @@ -120,14 +112,6 @@ isc_buffer_available(isc_buffer_t *b, isc_region_t *r) { r->length = b->length - b->used; } -unsigned int -isc_buffer_availablecount(isc_buffer_t *b) -{ - REQUIRE(ISC_BUFFER_VALID(b)); - - return (b->length - b->used); -} - void isc_buffer_add(isc_buffer_t *b, unsigned int n) { /* diff --git a/lib/isc/bufferlist.c b/lib/isc/bufferlist.c index f701d1ef4e..945578a003 100644 --- a/lib/isc/bufferlist.c +++ b/lib/isc/bufferlist.c @@ -34,7 +34,7 @@ isc_bufferlist_usedcount(isc_bufferlist_t *bl) buffer = ISC_LIST_HEAD(*bl); while (buffer != NULL) { REQUIRE(ISC_BUFFER_VALID(buffer)); - length += buffer->used; + length += ISC_BUFFER_USEDCOUNT(buffer); buffer = ISC_LIST_NEXT(buffer, link); } @@ -53,7 +53,7 @@ isc_bufferlist_availablecount(isc_bufferlist_t *bl) buffer = ISC_LIST_HEAD(*bl); while (buffer != NULL) { REQUIRE(ISC_BUFFER_VALID(buffer)); - length += (buffer->length - buffer->used); + length += ISC_BUFFER_AVAILABLECOUNT(buffer); buffer = ISC_LIST_NEXT(buffer, link); } diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index a265b8ff60..86f4618f26 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -117,6 +117,23 @@ ISC_LANG_BEGINDECLS #define ISC_BUFFER_VALID(b) ((b) != NULL && \ (b)->magic == ISC_BUFFER_MAGIC) +/* + * The following macros MUST be used only on valid buffers. It is the + * caller's responsibility to ensure this by using the ISC_BUFFER_VALID + * check above, or by calling another isc_buffer_*() function (rather than + * another macro.) + */ + +/* + * Get the length of the used region of buffer "b" + */ +#define ISC_BUFFER_USEDCOUNT(b) ((b)->used) + +/* + * Get the length of the available region of buffer "b" + */ +#define ISC_BUFFER_AVAILABLECOUNT(b) ((b)->length - (b)->used) + /*** *** Types ***/ @@ -254,16 +271,6 @@ isc_buffer_used(isc_buffer_t *b, isc_region_t *r); * 'r' points to a region structure. */ -unsigned int -isc_buffer_usedcount(isc_buffer_t *b); -/* - * Return the size of the used region of buffer 'b' - * - * Requires: - * - * 'b' is a valid buffer. - */ - void isc_buffer_available(isc_buffer_t *b, isc_region_t *r); /* @@ -276,16 +283,6 @@ isc_buffer_available(isc_buffer_t *b, isc_region_t *r); * 'r' points to a region structure. */ -unsigned int -isc_buffer_availablecount(isc_buffer_t *b); -/* - * Return the size of the available region of buffer 'b' - * - * Requires: - * - * 'b' is a valid buffer. - */ - void isc_buffer_add(isc_buffer_t *b, unsigned int n); /* diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index a9f926a54e..11e25bfb37 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -350,10 +350,10 @@ build_msghdr_send(isc_socket_t *sock, isc_socketevent_t *dev, */ skip_count = dev->n; while (buffer != NULL) { - isc_buffer_used(buffer, &used); - if (skip_count < used.length) + REQUIRE(ISC_BUFFER_VALID(buffer)); + if (skip_count < ISC_BUFFER_USEDCOUNT(buffer)) break; - skip_count -= used.length; + skip_count -= ISC_BUFFER_USEDCOUNT(buffer); buffer = ISC_LIST_NEXT(buffer, link); } @@ -447,8 +447,8 @@ build_msghdr_recv(isc_socket_t *sock, isc_socketevent_t *dev, * Skip empty buffers. */ while (buffer != NULL) { - isc_buffer_available(buffer, &available); - if (available.length != 0) + REQUIRE(ISC_BUFFER_VALID(buffer)); + if (ISC_BUFFER_AVAILABLECOUNT(buffer) != 0) break; buffer = ISC_LIST_NEXT(buffer, link); } @@ -539,7 +539,6 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) size_t actual_count; struct msghdr msghdr; isc_buffer_t *buffer; - isc_region_t available; build_msghdr_recv(sock, dev, &msghdr, iov, ISC_SOCKET_MAXSCATTERGATHER, &read_count); @@ -613,10 +612,11 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) actual_count = cc; buffer = ISC_LIST_HEAD(dev->bufferlist); while (buffer != NULL && actual_count > 0) { - isc_buffer_available(buffer, &available); - if (available.length <= actual_count) { - actual_count -= available.length; - isc_buffer_add(buffer, available.length); + REQUIRE(ISC_BUFFER_VALID(buffer)); + if (ISC_BUFFER_AVAILABLECOUNT(buffer) <= actual_count) { + actual_count -= ISC_BUFFER_AVAILABLECOUNT(buffer); + isc_buffer_add(buffer, + ISC_BUFFER_AVAILABLECOUNT(buffer)); } else { isc_buffer_add(buffer, actual_count); actual_count = 0;