Add stream avail() methods

Makes it more readable to write code that needs to know how much
data/space is available in a stream.
This commit is contained in:
Pierre Ossman
2020-05-19 20:45:22 +02:00
committed by Lauri Kasanen
parent 910fd8fa3e
commit 7f90205cf2
13 changed files with 38 additions and 22 deletions

View File

@@ -129,7 +129,7 @@ size_t FdOutStream::overrun(size_t itemSize, size_t nItems)
flush();
// Still not enough space?
if (itemSize > (size_t)(end - ptr)) {
if (itemSize > avail()) {
// Can we shuffle things around?
// (don't do this if it gains us less than 25%)
if (((size_t)(sentUpTo - start) > bufSize / 4) &&
@@ -150,7 +150,7 @@ size_t FdOutStream::overrun(size_t itemSize, size_t nItems)
}
size_t nAvail;
nAvail = (end - ptr) / itemSize;
nAvail = avail() / itemSize;
if (nAvail < nItems)
return nAvail;