--- libelwix/src/ring.c 2025/09/26 09:22:24 1.1.2.2 +++ libelwix/src/ring.c 2025/09/26 10:13:57 1.1.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: ring.c,v 1.1.2.2 2025/09/26 09:22:24 misho Exp $ +* $Id: ring.c,v 1.1.2.4 2025/09/26 10:13:57 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -161,8 +161,10 @@ rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len) int h, t, n; struct iovec *iov; - if (!rbuf) + if (!rbuf || !rbuf->rb_buffer) return -1; + if (!rbuf->rb_bufnum) + return 1; h = atomic_load_explicit(&rbuf->rb_head, memory_order_relaxed); t = atomic_load_explicit(&rbuf->rb_tail, memory_order_acquire); @@ -191,8 +193,10 @@ rbuf_dequeue(ringbuf_t *rbuf, struct iovec *out) { int h, t, n; - if (!rbuf) + if (!rbuf || !rbuf->rb_buffer) return -1; + if (!rbuf->rb_bufnum) + return 1; h = atomic_load_explicit(&rbuf->rb_head, memory_order_acquire); t = atomic_load_explicit(&rbuf->rb_tail, memory_order_relaxed); @@ -202,7 +206,7 @@ rbuf_dequeue(ringbuf_t *rbuf, struct iovec *out) return 1; if (out) - out = rbuf->rb_buffer + t; + *out = rbuf->rb_buffer[t]; atomic_store_explicit(&rbuf->rb_tail, n, memory_order_release); return 0;