--- a/src/ucx/cx/buffer.h Sat Nov 29 19:03:52 2025 +0100 +++ b/src/ucx/cx/buffer.h Sun Nov 30 18:25:55 2025 +0100 @@ -118,7 +118,7 @@ /** * The maximum number of blocks to flush in one cycle. * - * @attention while it is guaranteed that cxBufferFlush() will not flush + * @attention While it is guaranteed that cxBufferFlush() will not flush * more blocks, this is not necessarily the case for cxBufferWrite(). * After performing a flush cycle, cxBufferWrite() will retry the write * operation and potentially trigger another flush cycle, until the @@ -388,6 +388,20 @@ CX_EXPORT int cxBufferSeek(CxBuffer *buffer, off_t offset, int whence); /** + * Discards items from the end of the buffer. + * + * When the current position points to a byte that gets discarded, + * the position is set to the buffer size. + * + * @param buffer the buffer + * @param size the size of one item + * @param nitems the number of items to discard + * @return the actual number of discarded items + */ +cx_attr_nonnull +CX_EXPORT size_t cxBufferPop(CxBuffer *buffer, size_t size, size_t nitems); + +/** * Clears the buffer by resetting the position and deleting the data. * * The data is deleted by zeroing it with a call to memset(). @@ -425,11 +439,30 @@ cx_attr_nonnull cx_attr_nodiscard CX_EXPORT bool cxBufferEof(const CxBuffer *buffer); +/** + * Ensures that the buffer has the required capacity. + * + * If the current capacity is not sufficient, the buffer will be extended. + * + * This function will reserve no more bytes than requested, in contrast to + * cxBufferMinimumCapacity(), which may reserve more bytes to improve the + * number of future necessary reallocations. + * + * @param buffer the buffer + * @param capacity the required capacity for this buffer + * @retval zero the capacity was already sufficient or successfully increased + * @retval non-zero on allocation failure + * @see cxBufferShrink() + * @see cxBufferMinimumCapacity() + */ +cx_attr_nonnull +CX_EXPORT int cxBufferReserve(CxBuffer *buffer, size_t capacity); /** * Ensures that the buffer has a minimum capacity. * - * If the current capacity is not sufficient, the buffer will be extended. + * If the current capacity is not sufficient, the buffer will be generously + * extended. * * The new capacity will be a power of two until the system's page size is reached. * Then, the new capacity will be a multiple of the page size. @@ -438,6 +471,7 @@ * @param capacity the minimum required capacity for this buffer * @retval zero the capacity was already sufficient or successfully increased * @retval non-zero on allocation failure + * @see cxBufferReserve() * @see cxBufferShrink() */ cx_attr_nonnull @@ -457,6 +491,7 @@ * * @param buffer the buffer * @param reserve the number of bytes that shall remain reserved + * @see cxBufferReserve() * @see cxBufferMinimumCapacity() */ cx_attr_nonnull