summaryrefslogtreecommitdiff
path: root/kern/cbuf.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-17 18:45:31 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-17 18:48:58 +0200
commit0a5af0a62ba2ed1c17404b1dd8ed15b0ff41abf7 (patch)
treee6e97bfdb129cd9a4a8e4db90b10460d71a17b1e /kern/cbuf.h
parentbf32d26490a6fd688194f67856563f0a5a843668 (diff)
kern/cbuf: implement buffered reads and writes
This change brings an interface for fast buffered accesses to the content of a circular buffer, and also an interface to write into a circular buffer at custom locations, in exchange for a small interface break of cbuf_read.
Diffstat (limited to 'kern/cbuf.h')
-rw-r--r--kern/cbuf.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/kern/cbuf.h b/kern/cbuf.h
index b675fd5..0cac54a 100644
--- a/kern/cbuf.h
+++ b/kern/cbuf.h
@@ -92,12 +92,25 @@ void cbuf_push(struct cbuf *cbuf, char byte);
int cbuf_pop(struct cbuf *cbuf, char *bytep);
/*
- * Read a byte at a specific location.
+ * Write into a circular buffer at a specific location.
*
* If the given index is outside buffer boundaries, ERROR_INVAL is returned.
- * Otherwise the byte is stored at the bytep address and 0 is returned.
- * The buffer isn't changed by this operation.
+ * Otherwise size bytes are copied into the circular buffer. If the range
+ * in the circular buffer goes beyond its end, the end index is updated as
+ * appropriate. If the buffer is full when extending its end, the oldest
+ * bytes are overwritten and the start index is updated accordingly.
*/
-int cbuf_read(const struct cbuf *cbuf, size_t index, char *bytep);
+int cbuf_write(struct cbuf *cbuf, size_t index, const char *buf, size_t size);
+
+/*
+ * Read from a circular buffer at a specific location.
+ *
+ * If the given index is outside buffer boundaries, ERROR_INVAL is returned.
+ * Otherwise at most *sizep bytes are copied into the given character buffer,
+ * and *sizep is updated to the number of bytes actually copied.
+ *
+ * The circular buffer isn't changed by this operation.
+ */
+int cbuf_read(const struct cbuf *cbuf, size_t index, char *buf, size_t *sizep);
#endif /* _KERN_CBUF_H */