17#ifndef BASIC_IO_OUTPUT_HPP_INCLUDED
18#define BASIC_IO_OUTPUT_HPP_INCLUDED
21#include <system_error>
25#include "nonstd/expected.hpp"
27#include "buffer/shared_buffer.hpp"
56template <
typename IOT>
60 std::weak_ptr<IOT> m_ioh_wptr;
63 using endpoint_type =
typename IOT::endpoint_type;
91 bool is_valid() const noexcept {
return !m_ioh_wptr.expired(); }
103 return detail::wp_access<output_queue_stats>( m_ioh_wptr,
104 [] (std::shared_ptr<IOT> sp) {
return sp->get_output_queue_stats(); } );
121 bool send(
const void* buf, std::size_t sz)
const {
return send(chops::const_shared_buffer(buf, sz)); }
134 bool send(
const chops::const_shared_buffer& buf)
const {
135 auto sp = m_ioh_wptr.lock();
136 return sp ? sp->send(buf) :
false;
161 bool send(chops::mutable_shared_buffer&& buf)
const {
162 return send(chops::const_shared_buffer(std::move(buf)));
184 bool send(
const void* buf, std::size_t sz,
const endpoint_type& endp)
const {
185 return send(chops::const_shared_buffer(buf, sz), endp);
202 bool send(
const chops::const_shared_buffer& buf,
const endpoint_type& endp)
const {
203 auto sp = m_ioh_wptr.lock();
204 return sp ? sp->send(buf, endp) :
false;
222 bool send(chops::mutable_shared_buffer&& buf,
const endpoint_type& endp)
const {
223 return send(chops::const_shared_buffer(std::move(buf)), endp);
238 return (m_ioh_wptr.lock() == rhs.m_ioh_wptr.lock());
251 return (m_ioh_wptr.lock() < rhs.m_ioh_wptr.lock());
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 endpoint_type &endp) const
Send a buffer to a specific destination endpoint (address and port), implemented only for UDP IO hand...
Definition basic_io_output.hpp:184
bool send(chops::mutable_shared_buffer &&buf) const
Move a reference counted buffer and send it through the associated network IO handler.
Definition basic_io_output.hpp:161
bool operator<(const basic_io_output< IOT > &rhs) const noexcept
Compare two basic_io_output objects for ordering purposes.
Definition basic_io_output.hpp:250
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
bool operator==(const basic_io_output< IOT > &rhs) const noexcept
Compare two basic_io_output objects for equality.
Definition basic_io_output.hpp:237
bool is_valid() const noexcept
Query whether an IO handler is associated with this object.
Definition basic_io_output.hpp:91
auto get_output_queue_stats() const -> nonstd::expected< output_queue_stats, std::error_code >
Return output queue statistics, allowing application monitoring of output queue sizes.
Definition basic_io_output.hpp:101
basic_io_output()=default
Default construct a basic_io_output.
bool send(const chops::const_shared_buffer &buf) const
Send a reference counted buffer through the associated network IO handler.
Definition basic_io_output.hpp:134
bool send(const chops::const_shared_buffer &buf, const endpoint_type &endp) const
Send a reference counted buffer to a specific destination endpoint (address and port),...
Definition basic_io_output.hpp:202
basic_io_output(std::weak_ptr< IOT > p) noexcept
Construct a std::weak_ptr to an internal IO handler. This constructor is for internal use only and no...
Definition basic_io_output.hpp:80
bool send(chops::mutable_shared_buffer &&buf, const endpoint_type &endp) const
Move a reference counted buffer and send it through the associated network IO handler,...
Definition basic_io_output.hpp:222
Structures containing statistics gathered on internal queues.
output_queue_stats provides information on the internal output queue.
Definition queue_stats.hpp:29
Common code for accessing std::weak_ptr referenced objects, used in basic_io_interface and net_entity...