]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
added fr_ring_buffer_start()
authorAlan T. DeKok <aland@freeradius.org>
Sun, 20 Nov 2016 01:52:45 +0000 (20:52 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 20 Nov 2016 14:56:20 +0000 (09:56 -0500)
Which gets "pointer + size" to the data at the start of the
ring buffer.

src/util/ring_buffer.c
src/util/ring_buffer.h

index fc2ecca50c8486008dc3abd0803d4455e932b47b..db0ebf70822f33e87a181e75138dc12741b26181 100644 (file)
@@ -483,3 +483,23 @@ size_t fr_ring_buffer_used(fr_ring_buffer_t *rb)
 
        return size;
 }
+
+/** Get a pointer to the data at the start of the ring buffer.
+ *
+ * @param[in] rb a ring buffer
+ * @param[out] p_start pointer to data at the start of the ring buffer
+ * @param[in] p_size size of the allocated block at the start of the ring buffer.
+ * @return size of the used data in the ring buffer.
+ *     - <0 on error.
+ *      - 0 on success
+ */
+int fr_ring_buffer_start(fr_ring_buffer_t *rb, uint8_t **p_start, size_t *p_size)
+{
+#ifndef NDEBUG
+       (void) talloc_get_type_abort(rb, fr_ring_buffer_t);
+#endif
+
+       *p_start = rb->buffer + rb->data_start;
+       *p_size = (rb->data_end - rb->data_start);
+       return 0;
+}
index 699096cc24994a47d13bad136f96e5594b803b81..66e5ddd92538501000242064ce2fabce3b13fa28 100644 (file)
@@ -43,6 +43,8 @@ uint8_t *fr_ring_buffer_alloc(fr_ring_buffer_t *rb, size_t size) CC_HINT(nonnull
 uint8_t *fr_ring_buffer_reserve_split(fr_ring_buffer_t *dst, size_t reserve_size,
                                      fr_ring_buffer_t *src, size_t move_size) CC_HINT(nonnull);
 
+int fr_ring_buffer_start(fr_ring_buffer_t *dst, uint8_t **p_start, size_t *p_size);
+
 int fr_ring_buffer_free(fr_ring_buffer_t *rb, size_t size) CC_HINT(nonnull);
 
 int fr_ring_buffer_close(fr_ring_buffer_t *rb) CC_HINT(nonnull);