Simplify stream availability handling

Just have a simply number of bytes argument to avoid a lot of
complexity.
This commit is contained in:
Pierre Ossman
2020-05-19 21:07:05 +02:00
committed by Lauri Kasanen
parent 92c7695981
commit 57a3c3bba8
20 changed files with 67 additions and 132 deletions

View File

@@ -44,12 +44,12 @@ size_t BufferedInStream::pos()
return offset + ptr - start;
}
size_t BufferedInStream::overrun(size_t itemSize, size_t nItems, bool wait)
bool BufferedInStream::overrun(size_t needed, bool wait)
{
if (itemSize > bufSize)
if (needed > bufSize)
throw Exception("BufferedInStream overrun: "
"requested size of %lu bytes exceeds maximum of %lu bytes",
(long unsigned)itemSize, (long unsigned)bufSize);
(long unsigned)needed, (long unsigned)bufSize);
if (end - ptr != 0)
memmove(start, ptr, end - ptr);
@@ -58,15 +58,10 @@ size_t BufferedInStream::overrun(size_t itemSize, size_t nItems, bool wait)
end -= ptr - start;
ptr = start;
while (avail() < itemSize) {
while (avail() < needed) {
if (!fillBuffer(start + bufSize - end, wait))
return 0;
return false;
}
size_t nAvail;
nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;
return nItems;
return true;
}