diff options
Diffstat (limited to 'src/input/InputStream.cxx')
-rw-r--r-- | src/input/InputStream.cxx | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/input/InputStream.cxx b/src/input/InputStream.cxx index 44f726a62..bf6fd198e 100644 --- a/src/input/InputStream.cxx +++ b/src/input/InputStream.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -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(); } - |