AsyncBerkeley
Asynchronous Berkeley sockets. Simple.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
io::socket::message_buffer< Allocator > Class Template Reference

A container for managing buffers for scatter-gather I/O operations. More...

#include <io/socket/socket_message.hpp>

Public Types

using buffer_type = std::vector< native_buffer_type, Allocator >
 The underlying buffer type.
 
using iterator = typename buffer_type::iterator
 Iterator for the buffer.
 
using const_iterator = typename buffer_type::const_iterator
 Constant iterator for the buffer.
 
using size_type = typename buffer_type::size_type
 Size type for the buffer.
 

Public Member Functions

 message_buffer (const Allocator &alloc=Allocator()) noexcept(noexcept(Allocator()))
 Construct message buffer with a custom allocator.
 
template<ScatterGatherLike... Bufs>
constexpr message_buffer (const Bufs &...bufs) noexcept
 Construct a message_buffer from a list of scatter-gather buffers.
 
template<ScatterGatherLike Buf>
constexpr auto push_back (const Buf &buf) -> void
 Adds a buffer to the collection.
 
constexpr auto push_back (native_buffer_type buf) -> void
 Adds a native buffer to the collection.
 
template<typename... Args>
constexpr auto emplace_back (Args &&...args) -> decltype(auto)
 Constructs a native buffer in-place at the end of the collection.
 
constexpr auto begin () noexcept -> iterator
 Returns an iterator to the beginning of the buffer collection.
 
constexpr auto begin () const noexcept -> const_iterator
 Returns a const iterator to the beginning of the buffer collection.
 
constexpr auto end () noexcept -> iterator
 Returns an iterator to the end of the buffer collection.
 
constexpr auto end () const noexcept -> const_iterator
 Returns a const iterator to the end of the buffer collection.
 
constexpr auto size () const noexcept -> size_type
 Returns the number of buffers in the collection.
 
constexpr auto empty () const noexcept -> bool
 Checks if the buffer collection is empty.
 
constexpr operator bool () const noexcept
 Checks if the buffer collection is not empty.
 
auto operator+= (std::size_t len) noexcept -> message_buffer &
 Advances the buffers by a specified length.
 

Detailed Description

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
class io::socket::message_buffer< Allocator >

A container for managing buffers for scatter-gather I/O operations.

This class provides a convenient way to handle a collection of buffers that can be used in readv/writev (scatter/gather) style I/O operations.

Constructor & Destructor Documentation

◆ message_buffer() [1/2]

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
io::socket::message_buffer< Allocator >::message_buffer ( const Allocator &  alloc = Allocator())
noexcept

Construct message buffer with a custom allocator.

Parameters
allocThe allocator to use for the buffer.

◆ message_buffer() [2/2]

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
template<ScatterGatherLike... Bufs>
constexpr io::socket::message_buffer< Allocator >::message_buffer ( const Bufs &...  bufs)
constexprnoexcept

Construct a message_buffer from a list of scatter-gather buffers.

Template Parameters
BufsA variadic template argument determining the types of buffers.
Parameters
bufsThe variadic list of bufs to construct the message buffer from.

Member Function Documentation

◆ emplace_back()

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
template<typename... Args>
constexpr auto io::socket::message_buffer< Allocator >::emplace_back ( Args &&...  args) -> decltype(auto)
constexpr

Constructs a native buffer in-place at the end of the collection.

Template Parameters
ArgsThe types of the arguments to forward to the constructor of the native buffer.
Parameters
argsThe arguments to forward.
Returns
A reference to the constructed buffer.

◆ operator bool()

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
constexpr io::socket::message_buffer< Allocator >::operator bool ( ) const
explicitconstexprnoexcept

Checks if the buffer collection is not empty.

Returns
True if not empty, false otherwise.

◆ operator+=()

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
auto io::socket::message_buffer< Allocator >::operator+= ( std::size_t  len) -> message_buffer &
noexcept

Advances the buffers by a specified length.

This is useful for handling partial reads/writes. It adjusts the internal buffers to skip the given number of bytes.

Parameters
lenThe number of bytes to advance.
Returns
A reference to this scatter_gather_buffers object.

◆ push_back() [1/2]

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
template<ScatterGatherLike Buf>
constexpr auto io::socket::message_buffer< Allocator >::push_back ( const Buf &  buf) -> void
constexpr

Adds a buffer to the collection.

Template Parameters
BThe type of the buffer, which must satisfy the ScatterGatherLike concept.
Parameters
bufThe buffer to add.

◆ push_back() [2/2]

template<AllocatorLike Allocator = std::allocator<native_buffer_type>>
constexpr auto io::socket::message_buffer< Allocator >::push_back ( native_buffer_type  buf) -> void
constexpr

Adds a native buffer to the collection.

Parameters
bufThe native buffer to add.

The documentation for this class was generated from the following file: