Chops Net IP
Loading...
Searching...
No Matches
io_state_change.hpp
Go to the documentation of this file.
1
32#ifndef IO_STATE_CHANGE_HPP_INCLUDED
33#define IO_STATE_CHANGE_HPP_INCLUDED
34
35#include <cstddef> // std::size_t, std::byte
36#include <utility> // std::move
37
38#include "asio/ip/udp.hpp" // ip::udp::endpoint
39
41
43
44namespace chops {
45namespace net {
46
63template <typename MH>
65 MH&& msg_hdlr,
66 hdr_decoder_func hdr_func) {
67 return [hdr_size, hdr_func, mh = std::move(msg_hdlr)]
68 (tcp_io_interface io, std::size_t num, bool starting) {
69 if (starting) {
70 io.start_io(hdr_size, std::move(mh), hdr_func);
71 }
72 };
73}
74
92template <typename MH, typename MF>
93auto make_msg_frame_io_state_change (std::size_t hdr_size,
94 MH&& msg_hdlr,
95 MF&& msg_frame) {
96 return [hdr_size, mh = std::move(msg_hdlr), mf = std::move(msg_frame)]
97 (tcp_io_interface io, std::size_t num, bool starting) {
98 if (starting) {
99 io.start_io(hdr_size, std::move(mh), std::move(mf));
100 }
101 };
102}
103
119template <typename MH>
120auto make_delimiter_read_io_state_change (std::string_view delim, MH&& msg_hdlr) {
121 return [delim, mh = std::move(msg_hdlr)]
122 (tcp_io_interface io, std::size_t num, bool starting) {
123 if (starting) {
124 io.start_io(delim, std::move(mh));
125 }
126 };
127}
128
145template <typename MH, typename IOT = udp_io>
146auto make_read_io_state_change (std::size_t rd_size, MH&& msg_hdlr) {
147 return [rd_size, mh = std::move(msg_hdlr)]
148 (basic_io_interface<IOT> io, std::size_t num, bool starting) {
149 if (starting) {
150 io.start_io(rd_size, std::move(mh));
151 }
152 };
153}
154
162template <typename IOT>
164 return [] (basic_io_interface<IOT> io, std::size_t num, bool starting) {
165 if (starting) {
166 io.start_io();
167 }
168 };
169}
170
187template <typename MH>
188auto make_default_endp_io_state_change (const asio::ip::udp::endpoint& endp,
189 std::size_t max_size,
190 MH&& msg_hdlr) {
191 return [max_size, endp, mh = std::move(msg_hdlr)]
192 (udp_io_interface io, std::size_t num, bool starting) {
193 if (starting) {
194 io.start_io(endp, max_size, std::move(mh));
195 }
196 };
197}
198
209inline
210auto make_send_only_default_endp_io_state_change (const asio::ip::udp::endpoint& endp) {
211 return [endp] (udp_io_interface io, std::size_t num, bool starting) {
212 if (starting) {
213 io.start_io(endp);
214 }
215 };
216}
217
218} // end net namespace
219} // end chops namespace
220
221#endif
222
The basic_io_interface class template provides access to an underlying network IO handler (TCP or UDP...
Definition basic_io_interface.hpp:100
auto start_io(std::size_t header_size, MH &&msg_handler, MF &&msg_frame) -> nonstd::expected< void, std::error_code >
Enable IO processing for the associated network IO handler with message frame logic.
Definition basic_io_interface.hpp:265
auto make_default_endp_io_state_change(const asio::ip::udp::endpoint &endp, std::size_t max_size, MH &&msg_hdlr)
Create an IO state change function object parameters for UDP senders and receivers with a default des...
Definition io_state_change.hpp:188
auto make_msg_frame_io_state_change(std::size_t hdr_size, MH &&msg_hdlr, MF &&msg_frame)
Create an IO state change function object that is fully templatized on the message frame function obj...
Definition io_state_change.hpp:93
auto make_send_only_default_endp_io_state_change(const asio::ip::udp::endpoint &endp)
Create an IO state change function object parameters for UDP sending only with a default destination ...
Definition io_state_change.hpp:210
auto make_send_only_io_state_change()
Create an IO state change function object with parameters for sending only, whether UDP or TCP.
Definition io_state_change.hpp:163
auto make_simple_variable_len_msg_frame_io_state_change(std::size_t hdr_size, MH &&msg_hdlr, hdr_decoder_func hdr_func)
Create an IO state change function object with a simple variable length message frame function object...
Definition io_state_change.hpp:64
auto make_delimiter_read_io_state_change(std::string_view delim, MH &&msg_hdlr)
Create an IO state change function object parameters for TCP delimited reads.
Definition io_state_change.hpp:120
auto make_read_io_state_change(std::size_t rd_size, MH &&msg_hdlr)
Create an IO state change function object with parameters for UDP reads or fixed size TCP reads.
Definition io_state_change.hpp:146
IO type declarations, relating to the basic_io_interface and basic_io_output class templates.
Function object class and declaration for simple variable length TCP message framing.
Definition tcp_dsr.cpp:96