qb
2.0.0.0
C++17 Actor Framework
|
Asynchronous UDP client implementation. More...
#include <client.h>
Public Member Functions | |
client () noexcept | |
Constructor. | |
Public Member Functions inherited from qb::io::async::io< _Derived > | |
io ()=default | |
Default constructor. | |
io (IProtocol *protocol) noexcept | |
Constructor with an initial protocol instance. | |
io (io const &)=delete | |
Deleted copy constructor. | |
~io () noexcept | |
Destructor. | |
template<typename _Protocol, typename... _Args> | |
_Protocol * | switch_protocol (_Args &&...args) |
Switches to a new protocol for I/O processing, taking ownership. | |
void | clear_protocols () |
Clears all owned protocol instances. | |
IProtocol * | protocol () |
Gets a pointer to the current active protocol instance. | |
void | start () noexcept |
Starts bidirectional asynchronous I/O operations. | |
void | ready_to_read () noexcept |
Ensures the I/O watcher is listening for read events (EV_READ). | |
void | ready_to_write () noexcept |
Ensures the I/O watcher is listening for write events (EV_WRITE). | |
void | close_after_deliver () const noexcept |
Requests connection closure after all pending output data is delivered. | |
template<typename... _Args> | |
auto & | publish (_Args &&...args) noexcept |
Publishes data to the output buffer and ensures write readiness. | |
template<typename T> | |
auto & | operator<< (T &&data) |
Stream operator for publishing data. | |
void | disconnect (int reason=1) |
Initiates a graceful disconnection. | |
Public Member Functions inherited from qb::io::transport::udp | |
constexpr bool | is_secure () const noexcept |
Indicates that this transport implementation is not secure. | |
const udp::identity & | getSource () const noexcept |
Get the source udp::identity (endpoint) of the last successfully received datagram. | |
void | setDestination (udp::identity const &to) noexcept |
Set the destination udp::identity for subsequent outgoing datagrams sent via out() or operator<<. | |
auto & | out () |
Get the output proxy (ProxyOut) for stream-like sending to the current destination. | |
int | read () noexcept |
Read a single datagram from the UDP socket. | |
int | write () noexcept |
Write the next complete datagram from the output buffer to its destination. | |
char * | publish (char const *data, std::size_t size) noexcept |
Publish (enqueue) data to be sent to the current default destination (_remote_dest). | |
char * | publish_to (udp::identity const &to, char const *data, std::size_t size) noexcept |
Publish (enqueue) data to be sent to a specific udp::identity destination. | |
Public Member Functions inherited from qb::io::stream< io::udp::socket > | |
output_buffer_type & | out () noexcept |
Get the output buffer. | |
std::size_t | pendingWrite () const noexcept |
Get the number of bytes pending for writing. | |
int | write (std::enable_if_t< has_method_write< io::udp::socket, int, const char *, std::size_t >::value, Available > *=nullptr) noexcept |
Write data from the output buffer to the transport. | |
char * | publish (char const *data, std::size_t size) noexcept |
Add data to the output buffer for later writing. | |
void | close () noexcept |
Close the stream. | |
Public Member Functions inherited from qb::io::istream< _IO_ > | |
~istream () noexcept | |
Destructor. | |
_IO_ & | transport () noexcept |
Get the underlying transport object. | |
const _IO_ & | transport () const noexcept |
Get the underlying transport object (const version) | |
input_buffer_type & | in () noexcept |
Get the input buffer. | |
std::size_t | pendingRead () const noexcept |
Get the number of bytes available for reading. | |
template<typename Available = void> | |
int | read (std::enable_if_t< has_method_read< _IO_, int, char *, std::size_t >::value, Available > *=nullptr) noexcept |
Read data from the transport into the input buffer. | |
void | flush (std::size_t size) noexcept |
Remove data from the front of the input buffer. | |
void | eof () noexcept |
Handle end-of-file condition. | |
void | close () noexcept |
Close the stream. |
Static Public Attributes | |
static constexpr const bool | has_server |
Flag indicating server association (false for UDP clients) | |
Static Public Attributes inherited from qb::io::async::io< _Derived > | |
static constexpr const bool | has_server = false |
Indicates this component is not inherently a server. | |
Static Public Attributes inherited from qb::io::transport::udp | |
static constexpr const bool | has_reset_on_pending_read = true |
Indicates that this transport implementation resets its input buffer state when a read operation is pending (characteristic of datagram processing). | |
Static Public Attributes inherited from qb::io::stream< io::udp::socket > | |
static constexpr const bool | has_reset_on_pending_read |
Flag indicating whether the implementation resets pending reads. |
Additional Inherited Members | |
Public Types inherited from qb::io::async::io< _Derived > | |
typedef io< _Derived > | base_io_t |
Base I/O type alias for CRTP. | |
Public Types inherited from qb::io::stream< io::udp::socket > | |
using | transport_io_type |
Type of the underlying transport IO. | |
using | output_buffer_type |
Type of the output buffer. | |
Public Types inherited from qb::io::istream< _IO_ > | |
using | transport_io_type = _IO_ |
Type of the underlying transport IO. | |
using | input_buffer_type = qb::allocator::pipe<char> |
Type of the input buffer. | |
Public Attributes inherited from qb::io::transport::udp | |
friend | ProxyOut |
ProxyOut needs access to private members. | |
Protected Member Functions inherited from qb::io::async::io< _Derived > | |
void | dispose () |
Disposes of resources and finalizes disconnection for the I/O component. | |
Protected Member Functions inherited from qb::io::async::base< io< _Derived >, event::io > | |
base () | |
Constructor that registers the event watcher with the current listener. | |
~base () | |
Destructor that unregisters the event watcher. | |
Protected Attributes inherited from qb::io::async::base< io< _Derived >, event::io > | |
event::io & | _async_event |
Reference to the registered libev-based event watcher. | |
Protected Attributes inherited from qb::io::stream< io::udp::socket > | |
output_buffer_type | _out_buffer |
Buffer for outgoing data. | |
Protected Attributes inherited from qb::io::istream< _IO_ > | |
_IO_ | _in |
The underlying IO object. | |
input_buffer_type | _in_buffer |
Buffer for incoming data. |
Asynchronous UDP client implementation.
This template class implements an asynchronous UDP client. It combines the io class for asynchronous operations with the UDP transport for handling UDP communications. If the derived class defines a Protocol type, it will be used for processing UDP messages.
_Derived | The derived class type (CRTP pattern) |
|
inlinenoexcept |
Constructor.
Creates a new UDP client. If the derived class defines a Protocol type that is not void, an instance of that protocol is created and attached to the client.
|
staticconstexpr |
Flag indicating server association (false for UDP clients)