Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
buffer.h File Reference

Buffer abstraction (headers) More...

#include <stdint.h>
#include <glib.h>
Include dependency graph for buffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  imquic_buffer_chunk
 Buffer chunk. More...
 
struct  imquic_buffer
 Buffer made of multiple chunks (possibly with gaps) More...
 

Typedefs

typedef struct imquic_buffer_chunk imquic_buffer_chunk
 Buffer chunk.
 
typedef struct imquic_buffer imquic_buffer
 Buffer made of multiple chunks (possibly with gaps)
 

Functions

void imquic_buffer_chunk_free (imquic_buffer_chunk *chunk)
 Helper to quickly free a buffer chunk.
 
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.
 
int 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.
 
int 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 (headers)

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).

Typedef Documentation

◆ imquic_buffer

typedef struct imquic_buffer imquic_buffer

Buffer made of multiple chunks (possibly with gaps)

◆ imquic_buffer_chunk

typedef struct imquic_buffer_chunk imquic_buffer_chunk

Buffer chunk.

Function Documentation

◆ imquic_buffer_append()

int 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
0 in case of success, a negative integer 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()

int 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
0 in case of success, a negative integer otherwise