aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-21 17:10:20 +0100
committerMax Kellermann <max@duempel.org>2008-11-21 17:10:20 +0100
commit695d8051d255f89abf3ec73f806049ca77f4008a (patch)
tree3dd488969bfff043d76def2fcaa6416d5309e610 /src
parent46df0fd7dc3302df8961d51f9cc491ae499ada1c (diff)
downloadmpd-695d8051d255f89abf3ec73f806049ca77f4008a.tar.gz
mpd-695d8051d255f89abf3ec73f806049ca77f4008a.tar.xz
mpd-695d8051d255f89abf3ec73f806049ca77f4008a.zip
input_curl: try to seek by fast-forwarding the buffer
If the caller attempts to seek only a few bytes forward, chances are good that the offset is already in the buffer. In this case, simply fast-forward the buffer.
Diffstat (limited to 'src')
-rw-r--r--src/input_curl.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/input_curl.c b/src/input_curl.c
index ad575118d..551a44f4a 100644
--- a/src/input_curl.c
+++ b/src/input_curl.c
@@ -604,6 +604,32 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence)
if (offset < 0)
return false;
+ /* check if we can fast-forward the buffer */
+
+ while (offset > is->offset && !list_empty(&c->buffers)) {
+ struct list_head *rewind_head;
+ struct buffer *buffer = (struct buffer *)c->buffers.next;
+ size_t length;
+
+ if (!list_empty(&c->rewind) || is->offset == 0)
+ /* at the beginning or already writing the rewind
+ buffer list */
+ rewind_head = &c->rewind;
+ else
+ /* we don't need the rewind buffers anymore */
+ rewind_head = NULL;
+
+ length = buffer->size - buffer->consumed;
+ if (offset - is->offset < (off_t)length)
+ length = offset - is->offset;
+
+ consume_buffer(buffer, length, rewind_head);
+ is->offset += length;
+ }
+
+ if (offset == is->offset)
+ return true;
+
/* close the old connection and open a new one */
input_curl_easy_free(c);