20#ifndef SEND_TO_ALL_HPP_INCLUDED
21#define SEND_TO_ALL_HPP_INCLUDED
34#include "buffer/shared_buffer.hpp"
63template <
typename IOT>
66 using lock_guard = std::scoped_lock<std::mutex>;
68 using io_outs = std::vector<io_out>;
72 mutable std::mutex m_mutex;
82 lock_guard gd { m_mutex };
83 m_io_outs.push_back(io);
92 lock_guard gd { m_mutex };
93 std::erase_if (m_io_outs, [io] (
auto out) {
return io == out; } );
123 void send(chops::const_shared_buffer buf)
const {
124 lock_guard gd { m_mutex };
125 for (
const auto& io : m_io_outs) {
138 void send(chops::const_shared_buffer buf,
io_out cur_io)
const {
139 lock_guard gd { m_mutex };
140 for (
const auto& io : m_io_outs) {
141 if ( !(cur_io == io) ) {
156 void send(
const void* buf, std::size_t sz)
const {
157 send(chops::const_shared_buffer(buf, sz));
170 void send(
const void* buf, std::size_t sz,
io_out cur_io)
const {
171 send(chops::const_shared_buffer(buf, sz), cur_io);
180 void send(chops::mutable_shared_buffer&& buf)
const {
181 send(chops::const_shared_buffer(std::move(buf)));
192 void send(chops::mutable_shared_buffer&& buf,
io_out cur_io)
const {
193 send(chops::const_shared_buffer(std::move(buf)), cur_io);
199 std::size_t
size() const noexcept {
200 lock_guard gd { m_mutex };
201 return m_io_outs.size();
210 lock_guard gd { m_mutex };
basic_io_interface class template, providing start_io, stop_io, visit_socket, make_io_output and rela...
basic_io_output class template, providing send and get_output_queue_stats methods.
The basic_io_interface class template provides access to an underlying network IO handler (TCP or UDP...
Definition basic_io_interface.hpp:100
auto make_io_output() const -> nonstd::expected< basic_io_output< IOT >, std::error_code >
Make a basic_io_output object from the associated IO handler.
Definition basic_io_interface.hpp:153
The basic_io_output class template provides methods for sending data to an associated network IO hand...
Definition basic_io_output.hpp:57
Manage a collection of basic_io_output objects and provide a way to send data to all....
Definition send_to_all.hpp:64
void operator()(io_interface io, std::size_t, bool starting)
Interface for io_state_change parameter of start method.
Definition send_to_all.hpp:103
void send(chops::mutable_shared_buffer &&buf) const
Move the buffer from a writable reference counted buffer to an immutable reference counted buffer,...
Definition send_to_all.hpp:180
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...
Definition send_to_all.hpp:170
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.
Definition send_to_all.hpp:138
void remove_io_output(io_out io)
Remove a basic_io_output object from the collection.
Definition send_to_all.hpp:91
void send(chops::const_shared_buffer buf) const
Send a reference counted buffer to all basic_io_output objects.
Definition send_to_all.hpp:123
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.
Definition send_to_all.hpp:156
std::size_t size() const noexcept
Return the number of basic_io_output objects in the collection.
Definition send_to_all.hpp:199
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,...
Definition send_to_all.hpp:192
void add_io_output(io_out io)
Add a basic_io_output object to the collection.
Definition send_to_all.hpp:81
auto get_total_output_queue_stats() const noexcept
Return the sum total of output queue statistics.
Definition send_to_all.hpp:209
Functions that collect and deliver output_queue_stats from a sequence.
output_queue_stats accumulate_output_queue_stats(Iter beg, Iter end)
Accumulate output_queue_stats given a sequence of basic_io_output objects.
Definition output_queue_stats.hpp:48