Chops Net IP
Loading...
Searching...
No Matches
chops::net::send_to_all< IOT > Class Template Reference

Manage a collection of basic_io_output objects and provide a way to send data to all. or to all except a specific object. More...

#include <send_to_all.hpp>

Public Member Functions

void add_io_output (io_out io)
 Add a basic_io_output object to the collection.
 
void remove_io_output (io_out io)
 Remove a basic_io_output object from the collection.
 
void operator() (io_interface io, std::size_t, bool starting)
 Interface for io_state_change parameter of start method.
 
void send (chops::const_shared_buffer buf) const
 Send a reference counted buffer to all basic_io_output objects.
 
void send (chops::const_shared_buffer buf, io_out cur_io) const
 Send a reference counted buffer to all basic_io_output objects except cur_io.
 
void send (const void *buf, std::size_t sz) const
 Copy the bytes, create a reference counted buffer, then send it to all basic_io_output objects.
 
void send (const void *buf, std::size_t sz, io_out cur_io) const
 Copy the bytes, create a reference counted buffer, then send it to all basic_io_output objects except cur_io.
 
void send (chops::mutable_shared_buffer &&buf) const
 Move the buffer from a writable reference counted buffer to an immutable reference counted buffer, then send to all.
 
void send (chops::mutable_shared_buffer &&buf, io_out cur_io) const
 Move the buffer from a writable reference counted buffer to a immutable reference counted buffer, then send to all except cur_io.
 
std::size_t size () const noexcept
 Return the number of basic_io_output objects in the collection.
 
auto get_total_output_queue_stats () const noexcept
 Return the sum total of output queue statistics.
 

Detailed Description

template<typename IOT>
class chops::net::send_to_all< IOT >

Manage a collection of basic_io_output objects and provide a way to send data to all. or to all except a specific object.

In some use cases a buffer of data needs to be sent to multiple TCP connections or UDP destinations. This class manages a collection of basic_io_output objects and simplifies sending to all of them, or to all except a specific object.

A use case for "send to all but one @c io_output" is when "forward a message" functionality is desired. A message can come in on one connection and will be sent on to all other connections except for the incoming connection.

Buffer copying is kept to a minimum with this class. In particular, if the buffer of data to be sent is not yet in a reference counted buffer and the void pointer interface is used, only one buffer copy is made, and all TCP connections or UDP sockets will shared the same reference counted buffer, saving buffer copies across all of the connections or UDP sockets.

A function object operator overload is provided so that a std::ref to a send_to_all object can be used in composing function objects for io_state_change calls.

This class is thread-safe for concurrent access.

Member Function Documentation

◆ add_io_output()

template<typename IOT >
void chops::net::send_to_all< IOT >::add_io_output ( io_out io)
inline

Add a basic_io_output object to the collection.

Parameters
iobasic_io_output object to be added.

◆ get_total_output_queue_stats()

template<typename IOT >
auto chops::net::send_to_all< IOT >::get_total_output_queue_stats ( ) const
inlinenoexcept

Return the sum total of output queue statistics.

Returns
output_queue_stats object containing total counts.

◆ operator()()

template<typename IOT >
void chops::net::send_to_all< IOT >::operator() ( io_interface io,
std::size_t ,
bool starting )
inline

Interface for io_state_change parameter of start method.

See documentation of net_entity for start callback parameters.

◆ remove_io_output()

template<typename IOT >
void chops::net::send_to_all< IOT >::remove_io_output ( io_out io)
inline

Remove a basic_io_output object from the collection.

Parameters
iobasic_io_output object to be removed.

◆ send() [1/6]

template<typename IOT >
void chops::net::send_to_all< IOT >::send ( chops::const_shared_buffer buf) const
inline

Send a reference counted buffer to all basic_io_output objects.

Parameters
bufReference counted buffer to send.

◆ send() [2/6]

template<typename IOT >
void chops::net::send_to_all< IOT >::send ( chops::const_shared_buffer buf,
io_out cur_io ) const
inline

Send a reference counted buffer to all basic_io_output objects except cur_io.

Parameters
bufReference counted buffer to send.
cur_iobasic_io_output object to skip.

◆ send() [3/6]

template<typename IOT >
void chops::net::send_to_all< IOT >::send ( chops::mutable_shared_buffer && buf) const
inline

Move the buffer from a writable reference counted buffer to an immutable reference counted buffer, then send to all.

Parameters
bufReference counted buffer to send.

◆ send() [4/6]

template<typename IOT >
void chops::net::send_to_all< IOT >::send ( chops::mutable_shared_buffer && buf,
io_out cur_io ) const
inline

Move the buffer from a writable reference counted buffer to a immutable reference counted buffer, then send to all except cur_io.

Parameters
bufReference counted buffer to send.
cur_iobasic_io_output object to skip.

◆ send() [5/6]

template<typename IOT >
void chops::net::send_to_all< IOT >::send ( const void * buf,
std::size_t sz ) const
inline

Copy the bytes, create a reference counted buffer, then send it to all basic_io_output objects.

Parameters
bufPointer to char or std::byte array (other types can be used but will be treated as bytes).
szNumber of bytes to send.

◆ send() [6/6]

template<typename IOT >
void chops::net::send_to_all< IOT >::send ( const void * buf,
std::size_t sz,
io_out cur_io ) const
inline

Copy the bytes, create a reference counted buffer, then send it to all basic_io_output objects except cur_io.

Parameters
bufPointer to char or std::byte array.
szNumber of bytes to send.
cur_iobasic_io_output object to skip.

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