qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::tcp::connector< Socket_, Func_ > Class Template Reference

Handles asynchronous TCP connection establishment. More...

#include <connector.h>

Public Member Functions

 connector (uri const &remote, Func_ &&func, double timeout=0.)
 Constructor.
 connector (Socket_ &&existing_socket, uri const &remote, Func_ &&func, double timeout=0.)
 Constructor with an existing socket.
void on (event::io const &event)
 I/O event handler.

Detailed Description

template<typename Socket_, typename Func_>
class qb::io::async::tcp::connector< Socket_, Func_ >

Handles asynchronous TCP connection establishment.

This class template manages the process of establishing an asynchronous TCP connection. It attempts to connect immediately and, if that fails but the socket is in progress, sets up event handling to complete the connection when the socket becomes writable.

Template Parameters
Socket_The socket class type to use for the connection
Func_The callback function type that will be called on connection completion

Constructor & Destructor Documentation

◆ connector() [1/2]

template<typename Socket_, typename Func_>
qb::io::async::tcp::connector< Socket_, Func_ >::connector ( uri const & remote,
Func_ && func,
double timeout = 0. )
inline

Constructor.

Initiates an asynchronous connection to the specified remote endpoint. If the connection succeeds immediately, the callback is called right away. If the connection is in progress, event handling is set up. If the connection fails immediately, the callback is called with an empty socket.

Parameters
remoteURI of the remote endpoint to connect to
funcCallback function to call when connection completes
timeoutConnection timeout in seconds (0 = no timeout)

◆ connector() [2/2]

template<typename Socket_, typename Func_>
qb::io::async::tcp::connector< Socket_, Func_ >::connector ( Socket_ && existing_socket,
uri const & remote,
Func_ && func,
double timeout = 0. )
inline

Constructor with an existing socket.

Initiates an asynchronous connection to the specified remote endpoint using an existing socket. The provided socket is moved into the connector. If the connection succeeds immediately, the callback is called right away. If the connection is in progress, event handling is set up. If the connection fails immediately, the callback is called with an empty socket.

Parameters
existing_socketAn rvalue reference to an existing socket to be used for the connection
remoteURI of the remote endpoint to connect to
funcCallback function to call when connection completes
timeoutConnection timeout in seconds (0 = no timeout)

Member Function Documentation

◆ on()

template<typename Socket_, typename Func_>
void qb::io::async::tcp::connector< Socket_, Func_ >::on ( event::io const & event)
inline

I/O event handler.

This method is called when the socket becomes writable, indicating that the connection has completed or failed. It checks the socket for errors, completes the connection if successful, and calls the callback with the socket. The object deletes itself after completion.

Parameters
eventThe I/O event