Skip to content

File syn_netbuf.h

FileList > src > syntropic > util > syn_netbuf.h

Go to the source code of this file

Zero-Copy Packet Buffer Pool. More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_NetBuf
Zero-Copy Packet Buffer Descriptor.
struct SYN_NetBufPool
Packet Buffer Pool Descriptor.

Public Functions

Type Name
SYN_NetBuf * syn_netbuf_alloc (SYN_NetBufPool * pool, size_t headroom)
Allocate a packet buffer from the pool.
void syn_netbuf_free (SYN_NetBufPool * pool, SYN_NetBuf * buf)
Decrement reference counter and free buffer if count reaches 0.
size_t syn_netbuf_len (const SYN_NetBuf * buf)
Get payload length in bytes.
SYN_Status syn_netbuf_pool_init (SYN_NetBufPool * pool, SYN_NetBuf * bufs, uint8_t * raw_mem, size_t buf_count, size_t buf_size)
Initialize a packet buffer pool.
uint8_t * syn_netbuf_pull (SYN_NetBuf * buf, size_t len)
Strip header bytes from start of payload.
uint8_t * syn_netbuf_push (SYN_NetBuf * buf, size_t len)
Prepend header space before payload data.
uint8_t * syn_netbuf_put (SYN_NetBuf * buf, size_t len)
Append payload bytes to end of buffer.
void syn_netbuf_ref (SYN_NetBuf * buf)
Increment the reference counter of a packet buffer.

Macros

Type Name
define SYN_NETBUF_HEADROOM_DEFAULT 32U

Detailed Description

Provides a fixed-block memory pool manager for network/CAN packet buffers supporting reference counting, zero-copy header push/pull, and slicing.

Public Functions Documentation

function syn_netbuf_alloc

Allocate a packet buffer from the pool.

SYN_NetBuf * syn_netbuf_alloc (
    SYN_NetBufPool * pool,
    size_t headroom
) 

Parameters:

  • pool Pointer to pool descriptor.
  • headroom Initial headroom bytes reserved for network headers.

Returns:

Allocated SYN_NetBuf pointer, or NULL if pool is exhausted.


function syn_netbuf_free

Decrement reference counter and free buffer if count reaches 0.

void syn_netbuf_free (
    SYN_NetBufPool * pool,
    SYN_NetBuf * buf
) 

Parameters:

  • pool Pointer to pool descriptor.
  • buf Pointer to packet buffer.

function syn_netbuf_len

Get payload length in bytes.

size_t syn_netbuf_len (
    const SYN_NetBuf * buf
) 

Parameters:

  • buf Pointer to packet buffer.

Returns:

Payload length in bytes.


function syn_netbuf_pool_init

Initialize a packet buffer pool.

SYN_Status syn_netbuf_pool_init (
    SYN_NetBufPool * pool,
    SYN_NetBuf * bufs,
    uint8_t * raw_mem,
    size_t buf_count,
    size_t buf_size
) 

Parameters:

  • pool Pointer to pool descriptor.
  • bufs Array of buffer descriptors.
  • raw_mem Raw memory block storage.
  • buf_count Number of buffers in pool.
  • buf_size Size of each buffer block in bytes.

Returns:

SYN_OK on success.


function syn_netbuf_pull

Strip header bytes from start of payload.

uint8_t * syn_netbuf_pull (
    SYN_NetBuf * buf,
    size_t len
) 

Parameters:

  • buf Pointer to packet buffer.
  • len Bytes to strip.

Returns:

Pointer to new payload start, or NULL if payload shorter than len.


function syn_netbuf_push

Prepend header space before payload data.

uint8_t * syn_netbuf_push (
    SYN_NetBuf * buf,
    size_t len
) 

Parameters:

  • buf Pointer to packet buffer.
  • len Bytes to prepend.

Returns:

Pointer to new payload start, or NULL if headroom insufficient.


function syn_netbuf_put

Append payload bytes to end of buffer.

uint8_t * syn_netbuf_put (
    SYN_NetBuf * buf,
    size_t len
) 

Parameters:

  • buf Pointer to packet buffer.
  • len Bytes to append.

Returns:

Pointer to start of appended bytes, or NULL if tailroom insufficient.


function syn_netbuf_ref

Increment the reference counter of a packet buffer.

void syn_netbuf_ref (
    SYN_NetBuf * buf
) 

Parameters:

  • buf Pointer to packet buffer.

Macro Definition Documentation

define SYN_NETBUF_HEADROOM_DEFAULT

#define SYN_NETBUF_HEADROOM_DEFAULT `32U`


The documentation for this class was generated from the following file src/syntropic/util/syn_netbuf.h