From 46df0fd7dc3302df8961d51f9cc491ae499ada1c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 21 Nov 2008 16:57:55 +0100 Subject: [PATCH] input_curl: moved code to consume_buffer() Added some assertions. --- src/input_curl.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/input_curl.c b/src/input_curl.c index 09f10c3c6..ad575118d 100644 --- a/src/input_curl.c +++ b/src/input_curl.c @@ -207,6 +207,31 @@ input_curl_select(struct input_curl *c) return ret; } +/** + * Mark a part of the buffer object as consumed. + */ +static void +consume_buffer(struct buffer *buffer, size_t length, + struct list_head *rewind_head) +{ + assert(buffer != NULL); + assert(buffer->consumed < buffer->size); + + buffer->consumed += length; + if (buffer->consumed < buffer->size) + return; + + assert(buffer->consumed == buffer->size); + + list_del(&buffer->siblings); + + if (rewind_head != NULL) + /* append this buffer to the rewind buffer list */ + list_add_tail(&buffer->siblings, rewind_head); + else + g_free(buffer); +} + static size_t read_from_buffer(struct buffer *buffer, void *dest, size_t length, struct list_head *rewind_head) @@ -218,18 +243,7 @@ read_from_buffer(struct buffer *buffer, void *dest, size_t length, length = buffer->size - buffer->consumed; memcpy(dest, buffer->data + buffer->consumed, length); - - buffer->consumed += length; - if (buffer->consumed == buffer->size) { - list_del(&buffer->siblings); - - if (rewind_head != NULL) - /* append this buffer to the rewind buffer list */ - list_add_tail(&buffer->siblings, rewind_head); - else - g_free(buffer); - } - + consume_buffer(buffer, length, rewind_head); return length; }