diff options
author | Pierre Ossman <ossman@cendio.se> | 2020-05-19 21:07:05 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2020-05-21 11:34:22 +0200 |
commit | 186819080baea53410ae8d8100179a3874ac1e32 (patch) | |
tree | ddc4371f612a76114562f4a890a4c3ac3b3bfea6 /common/rdr/BufferedInStream.cxx | |
parent | e9425ac04d70481f7cb168a19bcbc47728f838c7 (diff) | |
download | tigervnc-186819080baea53410ae8d8100179a3874ac1e32.tar.gz tigervnc-186819080baea53410ae8d8100179a3874ac1e32.zip |
Simplify stream availability handling
Just have a simply number of bytes argument to avoid a lot of
complexity.
Diffstat (limited to 'common/rdr/BufferedInStream.cxx')
-rw-r--r-- | common/rdr/BufferedInStream.cxx | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 5083eb2d..5db3953a 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -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; } |