ring_buf
Loading...
Searching...
No Matches
Typedefs | Functions
ring_buf_item.h File Reference

Header file for ring buffer item functions. More...

#include "ring_buf.h"
Include dependency graph for ring_buf_item.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef uint16_t ring_buf_item_length_t
 Size of the ring buffer's item length.
 

Functions

int ring_buf_item_put (struct ring_buf *buf, const void *item, ring_buf_item_length_t length)
 Puts an item's length and content.
 
int ring_buf_item_get (struct ring_buf *buf, void *item, ring_buf_item_length_t *length)
 Gets an item from a ring buffer.
 

Detailed Description

Header file for ring buffer item functions.

This file contains the declarations for functions that handle putting and getting items in a ring buffer, where each item is prefixed with its length as a ring_buf_item_length_t 16-bit unsigned integer.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file ring_buf_item.h.

Typedef Documentation

◆ ring_buf_item_length_t

typedef uint16_t ring_buf_item_length_t

Size of the ring buffer's item length.

The length is the size of the item in bytes.

Definition at line 46 of file ring_buf_item.h.

Function Documentation

◆ ring_buf_item_get()

int ring_buf_item_get ( struct ring_buf buf,
void *  item,
ring_buf_item_length_t length 
)

Gets an item from a ring buffer.

Parameters
bufAddress of the ring buffer.
itemAddress of the item. Reserve sufficient space for the incoming bytes. There must be space for the largest possible item, since the largest one possible could be next.
lengthAddress of the length of the item on success.
Return values
0on success.
-EAGAINif the buffer is empty.
Note
The two-phase get claim cannot fail since a previous put succeeded. Do not mix item-based puts with plain puts.

Definition at line 43 of file ring_buf_item.c.

◆ ring_buf_item_put()

int ring_buf_item_put ( struct ring_buf buf,
const void *  item,
ring_buf_item_length_t  length 
)

Puts an item's length and content.

Parameters
bufAddress of the ring buffer.
itemAddress of item to put.
lengthNumber of bytes to put.
Return values
Zeroor greater on success, negative on error.
-EMSGSIZEif the buffer has insufficient space to put the item's length and data.
Note
Does not auto-acknowledge the put claim.

Definition at line 35 of file ring_buf_item.c.