diff --git a/core/ringbuffer.c b/core/ringbuffer.c index ffcb6dc..d488fc2 100644 --- a/core/ringbuffer.c +++ b/core/ringbuffer.c @@ -289,6 +289,14 @@ enum b_status b_ringbuffer_close_read_buffer( buf->r_read_ptr = 0; } + if (buf->r_read_ptr == buf->r_write_ptr) { + /* the ringbuffer is now empty. set both pointers to 0. + * this ensures that the whole buffer will be available + * contiguously to the next call to open_write_buffer */ + buf->r_read_ptr = 0; + buf->r_write_ptr = 0; + } + buf->r_opened_buf = NULL; buf->r_opened_capacity = 0; buf->r_flags &= ~B_RINGBUFFER_READ_LOCKED;