diff --git a/Foundation/include/Poco/FIFOBuffer.h b/Foundation/include/Poco/FIFOBuffer.h index 7f5022306..9c73b7e7a 100644 --- a/Foundation/include/Poco/FIFOBuffer.h +++ b/Foundation/include/Poco/FIFOBuffer.h @@ -284,7 +284,7 @@ public: std::size_t available() const /// Returns the size of the available portion of the buffer. { - return _buffer.size() - _used; + return size() - _used; } void drain(std::size_t length = 0) @@ -361,6 +361,9 @@ public: Mutex::ScopedLock lock(_mutex); if (_begin != 0) { + // Move the data to the start of the buffer so begin() and next() + // always return consistent pointers with each other and allow writing + // to the end of the buffer. std::memmove(_buffer.begin(), _buffer.begin() + _begin, _used * sizeof(T)); _begin = 0; } @@ -371,16 +374,7 @@ public: /// Returns the pointer to the next available position in the buffer. { Mutex::ScopedLock lock(_mutex); - if (available() == 0) - throw InvalidAccessException("Buffer is full."); - - if (_begin != 0) - { - std::memmove(_buffer.begin(), _buffer.begin() + _begin, _used * sizeof(T)); - _begin = 0; - } - - return _buffer.begin() + _used; + return begin() + _used; } T& operator [] (std::size_t index)