From 1b4e1afe4b3358e8b0c85c951d86cd5cb63a3dac Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 28 Oct 2024 12:00:16 +0100 Subject: [PATCH] sys/chunked_ringbuffer: let crb_end_chunk() return size of the chunk --- sys/chunked_ringbuffer/chunked_ringbuffer.c | 8 ++++---- sys/include/chunked_ringbuffer.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/chunked_ringbuffer/chunked_ringbuffer.c b/sys/chunked_ringbuffer/chunked_ringbuffer.c index a3c8e592b3f6..9eb0e35c8c0e 100644 --- a/sys/chunked_ringbuffer/chunked_ringbuffer.c +++ b/sys/chunked_ringbuffer/chunked_ringbuffer.c @@ -87,13 +87,13 @@ static unsigned _get_cur_len(chunk_ringbuf_t *rb) } } -bool crb_end_chunk(chunk_ringbuf_t *rb, bool keep) +unsigned crb_end_chunk(chunk_ringbuf_t *rb, bool keep) { int idx; /* no chunk was started */ if (rb->cur_start == NULL) { - return false; + return 0; } if (keep) { @@ -109,7 +109,7 @@ bool crb_end_chunk(chunk_ringbuf_t *rb, bool keep) } rb->cur = rb->cur_start; rb->cur_start = NULL; - return false; + return 0; } /* store complete chunk */ @@ -117,7 +117,7 @@ bool crb_end_chunk(chunk_ringbuf_t *rb, bool keep) rb->chunk_len[idx] = _get_cur_len(rb); rb->cur_start = NULL; - return true; + return rb->chunk_len[idx]; } bool crb_get_chunk_size(chunk_ringbuf_t *rb, size_t *len) diff --git a/sys/include/chunked_ringbuffer.h b/sys/include/chunked_ringbuffer.h index 9f1ac2fa24da..2b9b461c00a7 100644 --- a/sys/include/chunked_ringbuffer.h +++ b/sys/include/chunked_ringbuffer.h @@ -160,10 +160,10 @@ bool crb_add_bytes(chunk_ringbuf_t *rb, const void *data, size_t len); * @param[in] valid True if the chunk is valid and should be stored * False if the current chunk should be discarded * - * @return true If the chunk could be stored in the valid chunk array - * @return false If there is no more space in the valid chunk array + * @return size of chunk if the chunk could be stored in the valid chunk array + * @return 0 if there is no more space in the valid chunk array */ -bool crb_end_chunk(chunk_ringbuf_t *rb, bool valid); +unsigned crb_end_chunk(chunk_ringbuf_t *rb, bool valid); /** * @brief Add a complete chunk to the Ringbuffer