Chops Net IP
Loading...
Searching...
No Matches
chops::net::basic_io_output< IOT > Class Template Reference

The basic_io_output class template provides methods for sending data to an associated network IO handler (TCP or UDP IO handler) or getting output queue statistics. More...

#include <basic_io_output.hpp>

Public Types

using endpoint_type = typename IOT::endpoint_type
 

Public Member Functions

 basic_io_output ()=default
 Default construct a basic_io_output.
 
 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 not to be used by application code.
 
bool is_valid () const noexcept
 Query whether an IO handler is associated with this object.
 
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.
 
bool send (const void *buf, std::size_t sz) const
 Send a buffer of data through the associated network IO handler.
 
bool send (const chops::const_shared_buffer &buf) const
 Send a reference counted buffer through the associated network IO handler.
 
bool send (chops::mutable_shared_buffer &&buf) const
 Move a reference counted buffer and send it through the associated network IO handler.
 
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 handlers.
 
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), implemented only for UDP IO handlers.
 
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, implemented only for UDP IO handlers.
 
bool operator== (const basic_io_output< IOT > &rhs) const noexcept
 Compare two basic_io_output objects for equality.
 
bool operator< (const basic_io_output< IOT > &rhs) const noexcept
 Compare two basic_io_output objects for ordering purposes.
 

Related Symbols

(Note that these are not member symbols.)

using tcp_io = detail::tcp_io
 Using declaration for TCP based io, used to instantiate a basic_io_interface or basic_io_output type.
 
using udp_io = detail::udp_entity_io
 Using declaration for UDP based io, used to instantiate a basic_io_interface or basic_io_output type.
 
using tcp_io_output = basic_io_output<tcp_io>
 Using declaration for a TCP based basic_io_output type.
 
using udp_io_output = basic_io_output<udp_io>
 Using declaration for a UDP based basic_io_output type.
 

Detailed Description

template<typename IOT>
class chops::net::basic_io_output< IOT >

The basic_io_output class template provides methods for sending data to an associated network IO handler (TCP or UDP IO handler) or getting output queue statistics.

The basic_io_output class provides the primary application interface for network IO data sending, whether TCP or UDP. This class provides methods to send data and query output queue stats.

Unless default constructed, a basic_io_output object has an association to an IO handler object.

This class is a lightweight value class, allowing basic_io_output objects to be copied and used in multiple places in an application, all of them accessing the same network IO handler.

All basic_io_output send methods can be called concurrently from multiple threads.

Constructor & Destructor Documentation

◆ basic_io_output()

template<typename IOT >
chops::net::basic_io_output< IOT >::basic_io_output ( )
default

Default construct a basic_io_output.

A basic_io_output is not useful until an active basic_io_output is assigned into it.

Member Function Documentation

◆ get_output_queue_stats()

template<typename IOT >
auto chops::net::basic_io_output< IOT >::get_output_queue_stats ( ) const -> nonstd::expected<output_queue_stats, std::error_code>
inline

Return output queue statistics, allowing application monitoring of output queue sizes.

Returns
nonstd::expected - output_queue_stats on success; on error (if no associated IO handler), a std::error_code is returned.

◆ is_valid()

template<typename IOT >
bool chops::net::basic_io_output< IOT >::is_valid ( ) const
inlinenoexcept

Query whether an IO handler is associated with this object.

If true, an IO handler (e.g. TCP or UDP IO handler) is associated. However, the IO handler may be closed or shutting down, which means it will not queue any sent data.

Returns
true if associated with an IO handler.

◆ operator<()

template<typename IOT >
bool chops::net::basic_io_output< IOT >::operator< ( const basic_io_output< IOT > & rhs) const
inlinenoexcept

Compare two basic_io_output objects for ordering purposes.

The comparison is made through the std::shared_ptr operator< method. All invalid basic_io_output objects are less than valid ones. When both are valid, the address ordering is returned.

Returns
As described in the comments.

◆ operator==()

template<typename IOT >
bool chops::net::basic_io_output< IOT >::operator== ( const basic_io_output< IOT > & rhs) const
inlinenoexcept

Compare two basic_io_output objects for equality.

The comparison is made through the std::shared_ptr operator== method. The comparison is made on addresses if both basic_io_output objects are valid. If both basic_io_output objects are invalid, true is returned (this implies that all invalid basic_io_output objects are equivalent). If one is valid and the other invalid, false is returned.

Returns
As described in the comments.

◆ send() [1/6]

template<typename IOT >
bool chops::net::basic_io_output< IOT >::send ( chops::mutable_shared_buffer && buf) const
inline

Move a reference counted buffer and send it through the associated network IO handler.

To save a buffer copy, applications can create a chops::mutable_shared_buffer, fill it with data, then move it into a chops::const_shared_buffer. For example:

chops::mutable_shared_buffer buf;
// ... fill buf with data
an_io_output.send(std::move(buf));
buf.resize(0); // or whatever new desired size

This is a non-blocking call.

Parameters
bufchops::mutable_shared_buffer containing data.
Returns
true if buffer written or queued for output, false otherwise (no IO handler association, or IO handler stopped).

◆ send() [2/6]

template<typename IOT >
bool chops::net::basic_io_output< IOT >::send ( chops::mutable_shared_buffer && buf,
const endpoint_type & endp ) const
inline

Move a reference counted buffer and send it through the associated network IO handler, implemented only for UDP IO handlers.

See documentation for send without endpoint that moves a chops::mutable_shared_buffer. This is a non-blocking call.

Parameters
bufchops::mutable_shared_buffer containing data.
endpDestination asio::ip::udp::endpoint for the buffer.
Returns
true if buffer written or queued for output, false otherwise (no IO handler association, or IO handler stopped).

◆ send() [3/6]

template<typename IOT >
bool chops::net::basic_io_output< IOT >::send ( const chops::const_shared_buffer & buf) const
inline

Send a reference counted buffer through the associated network IO handler.

This is a non-blocking call.

Parameters
bufchops::const_shared_buffer containing data.
Returns
true if buffer written or queued for output, false otherwise (no IO handler association, or IO handler stopped).

◆ send() [4/6]

template<typename IOT >
bool chops::net::basic_io_output< IOT >::send ( const chops::const_shared_buffer & buf,
const endpoint_type & endp ) const
inline

Send a reference counted buffer to a specific destination endpoint (address and port), implemented only for UDP IO handlers.

This is a non-blocking call.

Parameters
bufchops::const_shared_buffer containing data.
endpDestination asio::ip::udp::endpoint for the buffer.
Returns
true if buffer written or queued for output, false otherwise (no IO handler association, or IO handler stopped).

◆ send() [5/6]

template<typename IOT >
bool chops::net::basic_io_output< IOT >::send ( const void * buf,
std::size_t sz ) const
inline

Send a buffer of data through the associated network IO handler.

The data is copied once into an internal reference counted buffer and then managed within the IO handler. This is a non-blocking call.

Parameters
bufPointer to buffer.
szSize of buffer.
Returns
true if buffer written or queued for output, false otherwise (no IO handler association, or IO handler stopped).

◆ send() [6/6]

template<typename IOT >
bool chops::net::basic_io_output< IOT >::send ( const void * buf,
std::size_t sz,
const endpoint_type & endp ) const
inline

Send a buffer to a specific destination endpoint (address and port), implemented only for UDP IO handlers.

Buffer data will be copied into an internal reference counted buffer. Calling this method is invalid for TCP IO handlers.

This is a non-blocking call.

Parameters
bufPointer to buffer.
szSize of buffer.
endpDestination asio::ip::udp::endpoint for the buffer.
Returns
true if buffer written or queued for output, false otherwise (no IO handler association, or IO handler stopped).

The documentation for this class was generated from the following files: