aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-21 16:57:55 +0100
committerMax Kellermann <max@duempel.org>2008-11-21 16:57:55 +0100
commit46df0fd7dc3302df8961d51f9cc491ae499ada1c (patch)
tree9817b3217d1668685965abc4eb1cdfebee17ba97
parent7779e4133a8f4298b04c857b3fd72e45a02f61f1 (diff)
downloadmpd-46df0fd7dc3302df8961d51f9cc491ae499ada1c.tar.gz
mpd-46df0fd7dc3302df8961d51f9cc491ae499ada1c.tar.xz
mpd-46df0fd7dc3302df8961d51f9cc491ae499ada1c.zip
input_curl: moved code to consume_buffer()
Added some assertions.
-rw-r--r--src/input_curl.c38
1 files 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;
}