Class NetworkBuffer

Inheritance Relationships

Derived Types

Class Documentation

class NetworkBuffer

A buffer to store network data.

The NetworkBuffer class is a simple buffer to store network data. It provides functionality to write data to the buffer and to retrieve the data stored in the buffer.

It either initializes its own memery or gets transferred a span of memory to use. In the first case it owns the memory and will free it when it is destroyed. In the second case it does not own the memory and will not free it.

Subclassed by netio3::asyncmsg::Buffer, netio3::libfabric::Buffer

Public Functions

inline explicit NetworkBuffer(std::size_t size)

Construct a new NetworkBuffer object allocating memory itself.

Parameters:

size – The size of the buffer

inline explicit NetworkBuffer(std::span<std::uint8_t> data)

Construct a new NetworkBuffer object using the given memory.

Parameters:

data – The memory to use

virtual ~NetworkBuffer() = default
NetworkBuffer(const NetworkBuffer&) = delete
NetworkBuffer(NetworkBuffer&&) = default
NetworkBuffer &operator=(const NetworkBuffer&) = delete
NetworkBuffer &operator=(NetworkBuffer&&) = default
inline void write(const std::span<const std::uint8_t> data)

Write data to the buffer.

Parameters:

data – The data to write

Throws:

std::runtime_error – if the buffer overflows

inline void write(const iovec &data)

Write data from an iovec to the buffer.

Parameters:

data – The data to write

Throws:

std::runtime_error – if the buffer overflows

inline void write(const std::integral auto value)

Write a value to the buffer.

Parameters:

value – The value to write

Throws:

std::runtime_error – if the buffer overflows

inline void reset()

Reset the buffer.

Does not actually clear the buffer but resets the position to the beginning.

inline std::span<const std::uint8_t> data() const

Get the data stored in the buffer.

Returns:

The data stored in the buffer

inline std::span<std::uint8_t> data()

Get the data stored in the buffer (mutable)

Required for C-APIs.

Returns:

The data stored in the buffer

inline std::size_t size() const

Get the size of the buffer.

Returns:

The size of the buffer

inline std::size_t pos() const

Get the position in the buffer.

Returns:

The position in the buffer

inline void mark_as_full()

Mark a buffer as being full.

@important To be used for performance measurements not for production.

inline void set_pos(std::size_t val)

Set the position to a given point.

Parameters:

val – The position to set @important To be used for performance measurements not for production.

inline void shuffle_to_front(std::size_t current_pos, std::size_t bytes_recv)

Implements some functionality needed by the POSIX backend. Remove it once the backend is deleted.

inline void shuffle_to_front2(std::size_t current_pos, std::size_t bytes_recv)

Implements some functionality needed by the POSIX backend. Remove it once the backend is deleted.