Loading...
Searching...
No Matches
buffer.c File Reference

Buffer abstraction. More...

#include "internal/buffer.h"
#include "imquic/debug.h"
Include dependency graph for buffer.c:

Functions

imquic_bufferimquic_buffer_create (uint64_t stream_id)
 Helper method to create a new buffer.
 
void imquic_buffer_destroy (imquic_buffer *buf)
 Helper method to destroy an existing buffer.
 
imquic_buffer_chunkimquic_buffer_chunk_create (uint8_t *data, uint64_t offset, uint64_t length)
 Helper to create a chunk out of existing data.
 
void imquic_buffer_chunk_free (imquic_buffer_chunk *chunk)
 Helper to quickly free a buffer chunk.
 
uint64_t imquic_buffer_put (imquic_buffer *buf, uint8_t *data, uint64_t offset, uint64_t length)
 Helper method to add new data to the buffer at a specific offset, as a new chunk.
 
uint64_t imquic_buffer_append (imquic_buffer *buf, uint8_t *data, uint64_t length)
 Helper method to add new data at the end of the buffer, as a new chunk.
 
imquic_buffer_chunkimquic_buffer_peek (imquic_buffer *buf)
 Helper method to peek at a buffer and check if there's data to read.
 
imquic_buffer_chunkimquic_buffer_get (imquic_buffer *buf)
 Helper method to get a chunk of data from the buffer.
 
void imquic_buffer_print (int level, imquic_buffer *buf)
 Helper method to print the contents of a buffer.
 

Detailed Description

Buffer abstraction.

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Abstraction of a chunked buffer, to be used either during CRYPTO exchanges in the Initial/Handshake phase, or with STREAM after a connection has been established. It provides a high level interface to adding chunks to the queue (in a gap-aware way), and to retrieving data in an ordered way (waiting in case gaps are encountered).

Function Documentation

◆ imquic_buffer_append()

uint64_t imquic_buffer_append ( imquic_buffer * buf,
uint8_t * data,
uint64_t length )

Helper method to add new data at the end of the buffer, as a new chunk.

Parameters
bufThe imquic_buffer instance to add data to
dataThe data to add to the buffer
lengthLength of this new data
Returns
The number of bytes actually added to the buffer in case of success, or 0 otherwise

◆ imquic_buffer_chunk_create()

imquic_buffer_chunk * imquic_buffer_chunk_create ( uint8_t * data,
uint64_t offset,
uint64_t length )

Helper to create a chunk out of existing data.

Parameters
dataThe data to put in the chunk
offsetThe offset of the data in the parent buffer
lengthThe size of the data
Returns
A pointer to a new imquic_buffer_chunk instance, if successful, or NULL otherwise

◆ imquic_buffer_chunk_free()

void imquic_buffer_chunk_free ( imquic_buffer_chunk * chunk)

Helper to quickly free a buffer chunk.

Parameters
chunkThe buffer chunk to free

◆ imquic_buffer_create()

imquic_buffer * imquic_buffer_create ( uint64_t stream_id)

Helper method to create a new buffer.

Parameters
stream_idStream ID this buffer belongs to (ignored when used with CRYPTO frames)
Returns
A pointer to a new imquic_buffer instance, if successful, or NULL otherwise

◆ imquic_buffer_destroy()

void imquic_buffer_destroy ( imquic_buffer * buf)

Helper method to destroy an existing buffer.

Parameters
bufThe imquic_buffer instance to destroy

◆ imquic_buffer_get()

imquic_buffer_chunk * imquic_buffer_get ( imquic_buffer * buf)

Helper method to get a chunk of data from the buffer.

Note
If there's data in the buffer, but the current offset points at a gap of data that hasn't been added yet, this function will not return anything, since this buffer API is conceived to read data in an ordered way. If data is found, the base offset is modified to point at the end of the returned chunk, which means a new imquic_buffer_peek or imquic_buffer_get call will point at the next chunk in the buffer.
Parameters
bufThe imquic_buffer instance to get the data from
Returns
A buffer chunk, if successful, or NULL otherwise

◆ imquic_buffer_peek()

imquic_buffer_chunk * imquic_buffer_peek ( imquic_buffer * buf)

Helper method to peek at a buffer and check if there's data to read.

Note
If there's data in the buffer, but the current offset points at a gap of data that hasn't been added yet, this function will not return anything, since this buffer API is conceived to read data in an ordered way. If data is found, the base offset is not modified, which means a new imquic_buffer_peek call will return the same chunk until imquic_buffer_get is called.
Parameters
bufThe imquic_buffer instance to peek
Returns
A buffer chunk, if successful, or NULL otherwise

◆ imquic_buffer_print()

void imquic_buffer_print ( int level,
imquic_buffer * buf )

Helper method to print the contents of a buffer.

Parameters
levelLog level at which this should be printed
bufThe imquic_buffer instance whose content should be printed

◆ imquic_buffer_put()

uint64_t imquic_buffer_put ( imquic_buffer * buf,
uint8_t * data,
uint64_t offset,
uint64_t length )

Helper method to add new data to the buffer at a specific offset, as a new chunk.

Note
In case the new data overlaps data already in the buffer, the new data is truncated accordingly to fit
Parameters
bufThe imquic_buffer instance to add data to
dataThe data to add to the buffer
offsetOffset in the overall buffer where this new data should be placed
lengthLength of this new data
Returns
The number of bytes actually added to the buffer in case of success, or 0 otherwise