limb 0.2.0

2024-01-09

buffer_rpeek(3)
limb manual
buffer_rpeek(3)

NAME

buffer_rpeek, buffer_rseek - peek/seek into a reading I/O buffer

SYNOPSIS

#include <limb/buffer.h>
void buffer_rpeek(buffer *buf, struct iovec v[2])
size_t buffer_rseek(buffer *buf, size_t len)

DESCRIPTION

The buffer_rpeek() macro allows to peek into a reading buffer's used space. The array of vectors pointed by v will be set to the in-use space inside the memory of the buffer pointed by buf, i.e. the data to be copied next by a call to buffer_get(3) or similar.

The buffer_rseek() macro will update the internals of the buffer pointed by buf to move past the next len bytes of data from its internal memory space, as if they had been read/consumed.

Note

Because a buffer's internal memory is kept as a circular buffer (see cbuffer.h(0) for more), the data might not be stored as a continuous block and requires a couple of vectors to possibly get the full space. Note than it is possible the second vector will be set to zero if not needed, however v should always point to an array of 2 elements.

Typically, one would use buffer_rpeek() to get the locations where to read from the buffer, and after all went well use buffer_rseek() to have said data "removed" from the buffer.

RETURN VALUE

The buffer_rseek() function returns the amount of bytes in use by which its internal buffer shrunk, which may be less than len (even 0 if the buffer was empty).

SEE ALSO

buffer_unget(3)

limb 0.1.0
2023-07-24
buffer_rpeek(3)