diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx index ec59680df..da41d3989 100644 --- a/src/input/AsyncInputStream.cxx +++ b/src/input/AsyncInputStream.cxx @@ -200,6 +200,12 @@ AsyncInputStream::Read(std::unique_lock &lock, memcpy(ptr, r.data, nbytes); buffer.Consume(nbytes); + if (buffer.empty()) + /* when the buffer becomes empty, reset its head and + tail so the next write can fill the whole buffer + and not just the part after the tail */ + buffer.Clear(); + offset += (offset_type)nbytes; if (paused && buffer.GetSize() < resume_at) diff --git a/src/input/ThreadInputStream.cxx b/src/input/ThreadInputStream.cxx index de9bae5ae..382ec8fdc 100644 --- a/src/input/ThreadInputStream.cxx +++ b/src/input/ThreadInputStream.cxx @@ -146,6 +146,14 @@ ThreadInputStream::Read(std::unique_lock &lock, size_t nbytes = std::min(read_size, r.size); memcpy(ptr, r.data, nbytes); buffer.Consume(nbytes); + + if (buffer.empty()) + /* when the buffer becomes empty, + reset its head and tail so the next + write can fill the whole buffer and + not just the part after the tail */ + buffer.Clear(); + wake_cond.notify_all(); offset += nbytes; return nbytes;