summaryrefslogtreecommitdiff
path: root/src/input/InputStream.cxx
diff options
context:
space:
mode:
authorThomas Guillem <thomas@gllm.fr>2015-06-05 16:27:10 +0200
committerMax Kellermann <max@duempel.org>2015-06-22 08:51:14 +0200
commit6e2d7445c50e30090e468f7c76fb95ff0c219183 (patch)
tree5c6c938d12ac53958c961f2526a659e3b0a208f3 /src/input/InputStream.cxx
parent90e7ace980fcfe4f894cd8e882fbfd2efba0b57d (diff)
InputStream: add ReadFull method
Convenient method that behave differently than Read, and that will be used by tag scanners. This method will return in case of error, if the whole data is read or is EOF is reached.
Diffstat (limited to 'src/input/InputStream.cxx')
-rw-r--r--src/input/InputStream.cxx31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/input/InputStream.cxx b/src/input/InputStream.cxx
index 419c4f07f..bf6fd198e 100644
--- a/src/input/InputStream.cxx
+++ b/src/input/InputStream.cxx
@@ -133,9 +133,38 @@ InputStream::LockRead(void *ptr, size_t _size, Error &error)
}
bool
+InputStream::ReadFull(void *_ptr, size_t _size, Error &error)
+{
+ uint8_t *ptr = (uint8_t *)_ptr;
+
+ size_t nbytes_total = 0;
+ while (_size > 0) {
+ size_t nbytes = Read(ptr + nbytes_total, _size, error);
+ if (nbytes == 0)
+ return false;
+
+ nbytes_total += nbytes;
+ _size -= nbytes;
+ }
+ return true;
+}
+
+bool
+InputStream::LockReadFull(void *ptr, size_t _size, Error &error)
+{
+#if !CLANG_CHECK_VERSION(3,6)
+ /* disabled on clang due to -Wtautological-pointer-compare */
+ assert(ptr != nullptr);
+#endif
+ assert(_size > 0);
+
+ const ScopeLock protect(mutex);
+ return ReadFull(ptr, _size, error);
+}
+
+bool
InputStream::LockIsEOF()
{
const ScopeLock protect(mutex);
return IsEOF();
}
-