18#ifndef BASIC_IO_INTERFACE_HPP_INCLUDED
19#define BASIC_IO_INTERFACE_HPP_INCLUDED
23#include <system_error>
27#include "nonstd/expected.hpp"
99template <
typename IOT>
102 std::weak_ptr<IOT> m_ioh_wptr;
105 using endpoint_type =
typename IOT::endpoint_type;
139 bool is_valid() const noexcept {
return !m_ioh_wptr.expired(); }
155 return detail::wp_access<basic_io_output<IOT>>( m_ioh_wptr,
169 nonstd::expected<
bool, std::error_code> {
170 return detail::wp_access<bool>( m_ioh_wptr,
171 [] (std::shared_ptr<IOT> sp) {
return sp->is_io_started(); } );
191 template <
typename F>
193 nonstd::expected<void, std::error_code> {
194 return detail::wp_access_void( m_ioh_wptr, [&func] (std::shared_ptr<IOT> sp) {
195 sp->visit_socket(func);
return std::error_code { }; } );
264 template <
typename MH,
typename MF>
265 auto start_io(std::size_t header_size, MH&& msg_handler, MF&& msg_frame) ->
266 nonstd::expected<void, std::error_code> {
267 return detail::wp_access_void( m_ioh_wptr,
268 [header_size, &msg_handler, &msg_frame] (std::shared_ptr<IOT> sp) {
269 return sp->start_io(header_size, msg_handler, msg_frame) ? std::error_code() :
270 std::make_error_code(net_ip_errc::io_already_started);
316 template <
typename MH>
318 nonstd::expected<void, std::error_code> {
319 return detail::wp_access_void( m_ioh_wptr,
320 [header_size, &msg_handler, func] (std::shared_ptr<IOT> sp) {
321 return sp->start_io(header_size, msg_handler, func) ? std::error_code() :
322 std::make_error_code(net_ip_errc::io_already_started);
363 template <
typename MH>
364 auto start_io(std::string_view delimiter, MH&& msg_handler) ->
365 nonstd::expected<void, std::error_code> {
366 return detail::wp_access_void( m_ioh_wptr,
367 [delimiter, &msg_handler] (std::shared_ptr<IOT> sp) {
368 return sp->start_io(delimiter, msg_handler) ? std::error_code() :
369 std::make_error_code(net_ip_errc::io_already_started);
413 template <
typename MH>
414 auto start_io(std::size_t read_size, MH&& msg_handler) ->
415 nonstd::expected<void, std::error_code> {
416 return detail::wp_access_void( m_ioh_wptr,
417 [read_size, &msg_handler] (std::shared_ptr<IOT> sp) {
418 return sp->start_io(read_size, msg_handler) ? std::error_code() :
419 std::make_error_code(net_ip_errc::io_already_started);
459 template <
typename MH>
460 auto start_io(
const endpoint_type& endp, std::size_t max_size, MH&& msg_handler) ->
461 nonstd::expected<void, std::error_code> {
462 return detail::wp_access_void( m_ioh_wptr,
463 [endp, max_size, &msg_handler] (std::shared_ptr<IOT> sp) {
464 return sp->start_io(endp, max_size, msg_handler) ? std::error_code() :
465 std::make_error_code(net_ip_errc::io_already_started);
486 nonstd::expected<void, std::error_code> {
487 return detail::wp_access_void( m_ioh_wptr,
488 [] (std::shared_ptr<IOT> sp) {
489 return sp->start_io() ? std::error_code() :
490 std::make_error_code(net_ip_errc::io_already_started);
511 nonstd::expected<void, std::error_code> {
512 return detail::wp_access_void( m_ioh_wptr,
513 [endp] (std::shared_ptr<IOT> sp) {
514 return sp->start_io(endp) ? std::error_code() :
515 std::make_error_code(net_ip_errc::io_already_started);
535 nonstd::expected<void, std::error_code> {
536 return detail::wp_access_void( m_ioh_wptr,
537 [] (std::shared_ptr<IOT> sp) {
538 return sp->stop_io() ? std::error_code() :
539 std::make_error_code(net_ip_errc::io_already_stopped);
555 return (m_ioh_wptr.lock() == rhs.m_ioh_wptr.lock());
568 return (m_ioh_wptr.lock() < rhs.m_ioh_wptr.lock());
582 return static_cast<const void*
>(m_ioh_wptr.lock().get());
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
std::size_t(*)(const std::byte *ptr, std::size_t sz) hdr_decoder_func
Signature for a variable length message header decoder function, used in one of the basic_io_interfac...
Definition simple_variable_len_msg_frame.hpp:51
auto visit_socket(F &&func) -> nonstd::expected< void, std::error_code >
Provide an application supplied function object which will be called with a reference to the associat...
Definition basic_io_interface.hpp:192
auto start_io(const endpoint_type &endp, std::size_t max_size, MH &&msg_handler) -> nonstd::expected< void, std::error_code >
Enable IO processing for the associated network IO handler with a maximum buffer size and a default d...
Definition basic_io_interface.hpp:460
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 start_io(std::size_t read_size, MH &&msg_handler) -> nonstd::expected< void, std::error_code >
Enable IO processing for the associated network IO handler with fixed or maximum buffer size logic.
Definition basic_io_interface.hpp:414
const void * get_ptr() const noexcept
Return a raw pointer to an associated IO handler.
Definition basic_io_interface.hpp:581
auto start_io(std::size_t header_size, MH &&msg_handler, hdr_decoder_func func) -> nonstd::expected< void, std::error_code >
Enable IO processing for the associated network IO handler with simple variable length message frame ...
Definition basic_io_interface.hpp:317
auto start_io(std::string_view delimiter, MH &&msg_handler) -> nonstd::expected< void, std::error_code >
Enable IO processing for the associated network IO handler with delimeter logic.
Definition basic_io_interface.hpp:364
basic_io_interface()=default
Default construct a basic_io_interface.
auto stop_io() -> nonstd::expected< void, std::error_code >
Stop IO processing and close the associated network IO handler.
Definition basic_io_interface.hpp:534
bool is_valid() const noexcept
Query whether an IO handler is associated with this object.
Definition basic_io_interface.hpp:139
basic_io_interface(std::weak_ptr< IOT > p) noexcept
Construct with a shared weak pointer to an internal IO handler, this is an internal constructor only ...
Definition basic_io_interface.hpp:129
bool operator==(const basic_io_interface< IOT > &rhs) const noexcept
Compare two basic_io_interface objects for equality.
Definition basic_io_interface.hpp:554
auto start_io() -> nonstd::expected< void, std::error_code >
Enable IO processing for the associated network IO handler with no incoming message handling.
Definition basic_io_interface.hpp:485
auto is_io_started() const -> nonstd::expected< bool, std::error_code >
Query whether an IO handler is in a started state or not.
Definition basic_io_interface.hpp:168
auto start_io(const endpoint_type &endp) -> nonstd::expected< void, std::error_code >
Enable IO processing for the associated network IO handler with no incoming message handling,...
Definition basic_io_interface.hpp:510
bool operator<(const basic_io_interface< IOT > &rhs) const noexcept
Compare two basic_io_interface objects for ordering purposes.
Definition basic_io_interface.hpp:567
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
Error codes, exception class, and error category within Chops net_ip library.
Function object class and declaration for simple variable length TCP message framing.
Common code for accessing std::weak_ptr referenced objects, used in basic_io_interface and net_entity...