summaryrefslogtreecommitdiff
path: root/lib/ringbuf.h
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-12-26 18:47:19 -0500
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-12-26 18:50:56 -0500
commita5080622b2de7c09393daa208a56606c068db1f3 (patch)
treeb4b4a8077fbfc45fbb1964686028f028eb097eca /lib/ringbuf.h
parent5318d8963816f607e8ab648eb17c784617b90270 (diff)
lib: add ringbuf_peek()
Peek functionality for ring buffers and associated tests. Also: * Slight optimization to avoid 0-byte memcpy() by changing > to >= * Add rv checks for some ringbuf_[put|get] calls that were missing them in the test Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/ringbuf.h')
-rw-r--r--lib/ringbuf.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/ringbuf.h b/lib/ringbuf.h
index af07c93a66..2288a2716f 100644
--- a/lib/ringbuf.h
+++ b/lib/ringbuf.h
@@ -84,6 +84,21 @@ size_t ringbuf_put(struct ringbuf *buf, const void *data, size_t size);
size_t ringbuf_get(struct ringbuf *buf, void *data, size_t size);
/*
+ * Peek data from the ring buffer.
+ *
+ * @param offset where to get the data from, in bytes offset from the
+ * start of the data
+ * @param data where to put the data
+ * @param size how much data to get
+ * @return number of bytes read into data; will be less than size
+ * if there was not enough data to read; will be -1 if the
+ * offset exceeds the amount of data left in the ring
+ * buffer
+ */
+size_t ringbuf_peek(struct ringbuf *buf, size_t offset, void *data,
+ size_t size);
+
+/*
* Reset buffer. Does not wipe.
*
* @param buf