The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Simple ring buffers for packet contents. More...
#include <freeradius-devel/io/ring_buffer.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/debug.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | fr_ring_buffer_s |
Functions | |
uint8_t * | fr_ring_buffer_alloc (fr_ring_buffer_t *rb, size_t size) |
Mark data as allocated. More... | |
int | fr_ring_buffer_close (fr_ring_buffer_t *rb) |
Close a ring buffer so that no further allocations can take place. More... | |
fr_ring_buffer_t * | fr_ring_buffer_create (TALLOC_CTX *ctx, size_t size) |
Create a ring buffer. More... | |
void | fr_ring_buffer_debug (fr_ring_buffer_t *rb, FILE *fp) |
Print debug information about the ring buffer. More... | |
int | fr_ring_buffer_free (fr_ring_buffer_t *rb, size_t size_to_free) |
Mark data as free,. More... | |
uint8_t * | fr_ring_buffer_reserve (fr_ring_buffer_t *rb, size_t size) |
Reserve room in the ring buffer. More... | |
size_t | fr_ring_buffer_size (fr_ring_buffer_t *rb) |
Get the size of the ring buffer. More... | |
int | fr_ring_buffer_start (fr_ring_buffer_t *rb, uint8_t **p_start, size_t *p_size) |
Get a pointer to the data at the start of the ring buffer. More... | |
size_t | fr_ring_buffer_used (fr_ring_buffer_t *rb) |
Get the amount of data used in a ring buffer. More... | |
Simple ring buffers for packet contents.
Definition in file ring_buffer.c.
struct fr_ring_buffer_s |
Definition at line 35 of file ring_buffer.c.
Data Fields | ||
---|---|---|
uint8_t * | buffer | actual start of the ring buffer |
bool | closed | whether allocations are closed |
size_t | data_end | end of used portion of the buffer |
size_t | data_start | start of used portion of the buffer |
size_t | reserved | amount of reserved data at write_offset |
size_t | size | Size of this ring buffer. |
size_t | write_offset | where writes are done |
uint8_t* fr_ring_buffer_alloc | ( | fr_ring_buffer_t * | rb, |
size_t | size | ||
) |
Mark data as allocated.
The size does not need to be a power of two. The application is responsible for doing cache-line alignment, if required.
The application does NOT need to call fr_ring_buffer_reserve() before calling this function.
If the allocation fails, the application should create a new ring buffer, and start allocating data there.
[in] | rb | a ring buffer |
[in] | size | to mark as "used" at the tail end of the buffer. |
Definition at line 196 of file ring_buffer.c.
int fr_ring_buffer_close | ( | fr_ring_buffer_t * | rb | ) |
Close a ring buffer so that no further allocations can take place.
Once the ring buffer is empty, it will be automatically freed. It's called "close" and not "delete", because the ring buffer will still be active until all data has been removed.
If you don't care about the data in the ring buffer, you can just call talloc_free() on it.
[in] | rb | a ring buffer |
Definition at line 407 of file ring_buffer.c.
fr_ring_buffer_t* fr_ring_buffer_create | ( | TALLOC_CTX * | ctx, |
size_t | size | ||
) |
Create a ring buffer.
The size provided will be rounded up to the next highest power of 2, if it's not already a power of 2.
The ring buffer manages how much room is reserved (i.e. available to write to), and used. The application is responsible for tracking the start of the reservation, and it's write offset within that reservation.
[in] | ctx | a talloc context |
[in] | size | of the raw ring buffer array to allocate. |
Definition at line 64 of file ring_buffer.c.
void fr_ring_buffer_debug | ( | fr_ring_buffer_t * | rb, |
FILE * | fp | ||
) |
Print debug information about the ring buffer.
[in] | rb | the ring buffer |
[in] | fp | the FILE where the messages are printed. |
Definition at line 485 of file ring_buffer.c.
int fr_ring_buffer_free | ( | fr_ring_buffer_t * | rb, |
size_t | size_to_free | ||
) |
Mark data as free,.
The size does not need to be a power of two. The application is responsible for doing cache alignment, if required. The application is responsible for tracking sizes of packets in the ring buffer.
If "unused" bytes are more than what's in the buffer, the used bytes are reset to zero.
[in] | rb | a ring buffer |
[in] | size_to_free | bytes to mark as "unused" in the buffer. |
Definition at line 304 of file ring_buffer.c.
uint8_t* fr_ring_buffer_reserve | ( | fr_ring_buffer_t * | rb, |
size_t | size | ||
) |
Reserve room in the ring buffer.
The size does not need to be a power of two. The application is responsible for doing cache alignment, if required.
If the reservation fails, the application should create a new ring buffer, and start reserving data there.
[in] | rb | a ring buffer |
[in] | size | to see if we can reserve |
Definition at line 119 of file ring_buffer.c.
size_t fr_ring_buffer_size | ( | fr_ring_buffer_t * | rb | ) |
Get the size of the ring buffer.
[in] | rb | a ring buffer |
Definition at line 423 of file ring_buffer.c.
int fr_ring_buffer_start | ( | fr_ring_buffer_t * | rb, |
uint8_t ** | p_start, | ||
size_t * | p_size | ||
) |
Get a pointer to the data at the start of the ring buffer.
[in] | rb | a ring buffer |
[out] | p_start | pointer to data at the start of the ring buffer |
[in] | p_size | size of the allocated block at the start of the ring buffer. |
Definition at line 464 of file ring_buffer.c.
size_t fr_ring_buffer_used | ( | fr_ring_buffer_t * | rb | ) |
Get the amount of data used in a ring buffer.
[in] | rb | a ring buffer |
Definition at line 437 of file ring_buffer.c.