qb
2.0.0.0
C++17 Actor Framework
|
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. |
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.
Socket_ | The socket class type to use for the connection |
Func_ | The callback function type that will be called on connection completion |
|
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.
remote | URI of the remote endpoint to connect to |
func | Callback function to call when connection completes |
timeout | Connection timeout in seconds (0 = no timeout) |
|
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.
existing_socket | An rvalue reference to an existing socket to be used for the connection |
remote | URI of the remote endpoint to connect to |
func | Callback function to call when connection completes |
timeout | Connection timeout in seconds (0 = no timeout) |
|
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.
event | The I/O event |