40#ifndef MSG_HANDLING_HPP_INCLUDED
41#define MSG_HANDLING_HPP_INCLUDED
58#include "asio/buffer.hpp"
59#include "asio/ip/udp.hpp"
60#include "asio/ip/address.hpp"
62#include "utility/byte_array.hpp"
64#include "serialize/extract_append.hpp"
65#include "buffer/shared_buffer.hpp"
73inline std::size_t decode_variable_len_msg_hdr(
const std::byte* buf_ptr, std::size_t sz) {
75 return extract_val<std::endian::big, std::uint16_t>(buf_ptr);
78inline chops::mutable_shared_buffer make_body_buf(std::string_view pre,
80 std::size_t num_body_chars) {
81 chops::mutable_shared_buffer buf(pre.data(), pre.size());
82 std::string body(num_body_chars, body_char);
83 return buf.append(body.data(), body.size());
86inline chops::const_shared_buffer make_variable_len_msg(
const chops::mutable_shared_buffer& body) {
87 assert(body.size() < std::numeric_limits<std::uint16_t>::max());
89 auto sz = append_val<std::endian::big, std::uint16_t>(hdr,
static_cast<std::uint16_t
>(body.size()));
90 chops::mutable_shared_buffer msg(hdr, 2);
91 return chops::const_shared_buffer(std::move(msg.append(body.data(), body.size())));
94inline chops::const_shared_buffer make_cr_lf_text_msg(
const chops::mutable_shared_buffer& body) {
95 chops::mutable_shared_buffer msg(body.data(), body.size());
96 auto ba = chops::make_byte_array(0x0D, 0x0A);
97 return chops::const_shared_buffer(std::move(msg.append(ba.data(), ba.size())));
100inline chops::const_shared_buffer make_lf_text_msg(
const chops::mutable_shared_buffer& body) {
101 chops::mutable_shared_buffer msg(body.data(), body.size());
102 auto ba = chops::make_byte_array(0x0A);
103 return chops::const_shared_buffer(std::move(msg.append(ba.data(), ba.size())));
107chops::const_shared_buffer make_empty_body_msg(F&& func) {
108 return func( chops::mutable_shared_buffer{ } );
111inline auto make_empty_variable_len_msg() {
return make_empty_body_msg(make_variable_len_msg); }
112inline auto make_empty_cr_lf_text_msg() {
return make_empty_body_msg(make_cr_lf_text_msg); }
113inline auto make_empty_lf_text_msg() {
return make_empty_body_msg(make_lf_text_msg); }
115using vec_buf = std::vector<chops::const_shared_buffer>;
118vec_buf make_msg_vec(F&& func, std::string_view pre,
char body_char,
int num_msgs) {
120 for (
int i : std::views::iota(0, num_msgs)) {
121 vec.push_back (func(make_body_buf(pre, body_char, i+1)));
126constexpr std::size_t fixed_size_buf_size = 33u;
128inline chops::const_shared_buffer make_fixed_size_buf() {
130 auto ba = chops::make_byte_array(0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
131 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
132 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
133 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
135 assert (ba.size() == fixed_size_buf_size);
136 return chops::const_shared_buffer(ba.data(), ba.size());
139inline vec_buf make_fixed_size_msg_vec(
int num_msgs) {
141 for (
int i : std::views::iota(0, num_msgs)) {
142 vec.push_back (make_fixed_size_buf());
147using test_counter = std::atomic_size_t;
149template <
typename IOT>
151 using endp_type =
typename IOT::endpoint_type;
152 using const_buf = asio::const_buffer;
157 msg_hdlr(
bool rep, test_counter& c) : reply(rep), cnt(c) { }
160 chops::const_shared_buffer sh_buf(buf.data(), buf.size());
161 if (sh_buf.size() > 2) {
164 bool r = io_out.
send(sh_buf, endp);
171 bool r = io_out.
send(sh_buf, endp);
178using test_prom = std::promise<std::size_t>;
182template <
typename IOT>
184 using endp_type =
typename IOT::endpoint_type;
185 using const_buf = asio::const_buffer;
192 prom(std::move(p)), max_cnt(m), cnt(c) { }
195 assert(buf.size() == fixed_size_buf_size);
213 m_sleep_time(sleep_time), m_log(log) { }
216 if (stats.output_queue_size == 0u) {
219 m_log <<
"Output queue size: " << stats.output_queue_size << std::endl;
220 std::this_thread::sleep_for(std::chrono::milliseconds(m_sleep_time));
basic_io_output class template, providing send and get_output_queue_stats methods.
The basic_io_output class template provides methods for sending data to an associated network IO hand...
Definition basic_io_output.hpp:57
bool send(const void *buf, std::size_t sz) const
Send a buffer of data through the associated network IO handler.
Definition basic_io_output.hpp:121
Definition msg_handling.hpp:206
Structures containing statistics gathered on internal queues.
output_queue_stats provides information on the internal output queue.
Definition queue_stats.hpp:29
Definition msg_handling.hpp:183
Definition msg_handling.hpp:150