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.
This commit is contained in:
@@ -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) {
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user