qb
2.0.0.0
C++17 Actor Framework
|
Class implementing TCP socket functionality for reliable, stream-oriented communication. More...
#include <socket.h>
Public Member Functions | |
socket ()=default | |
Default constructor. | |
socket (socket const &)=delete | |
Deleted copy constructor. | |
socket (socket &&)=default | |
Default move constructor. | |
socket & | operator= (socket &&)=default |
Default move assignment operator. | |
socket (io::socket &&sock) noexcept | |
Constructor from a generic qb::io::socket (move semantics). | |
socket & | operator= (io::socket &&sock) noexcept |
Move assignment operator from a generic qb::io::socket. | |
int | init (int af=AF_INET) noexcept |
Initialize (open) the TCP socket. | |
int | bind (qb::io::endpoint const &ep) noexcept |
Bind the socket to a specific local endpoint. | |
int | bind (qb::io::uri const &u) noexcept |
Bind the socket to an endpoint specified by a URI. | |
int | connect (qb::io::endpoint const &ep) noexcept |
Connect to a remote TCP endpoint. | |
int | connect (uri const &u) noexcept |
Connect to a remote TCP endpoint specified by a URI. | |
int | connect_v4 (std::string const &host, uint16_t port) noexcept |
Connect to an IPv4 TCP server. | |
int | connect_v6 (std::string const &host, uint16_t port) noexcept |
Connect to an IPv6 TCP server. | |
int | connect_un (std::string const &path) noexcept |
Connect to a Unix domain TCP-style socket. | |
int | n_connect (qb::io::endpoint const &ep) noexcept |
Initiate a non-blocking connect to a remote TCP endpoint. | |
void | connected () noexcept |
Called after a non-blocking connect attempt succeeds or needs to be finalized. | |
int | n_connect (uri const &u) noexcept |
Initiate a non-blocking connect to a remote TCP endpoint specified by a URI. | |
int | n_connect_v4 (std::string const &host, uint16_t port) noexcept |
Initiate a non-blocking connect to an IPv4 TCP server. | |
int | n_connect_v6 (std::string const &host, uint16_t port) noexcept |
Initiate a non-blocking connect to an IPv6 TCP server. | |
int | n_connect_un (std::string const &path) noexcept |
Initiate a non-blocking connect to a Unix domain TCP-style socket. | |
int | read (void *dest, std::size_t len) const noexcept |
Read data from the connected TCP socket. | |
int | write (const void *data, std::size_t size) const noexcept |
Write data to the connected TCP socket. | |
int | disconnect () const noexcept |
Disconnect the TCP socket. |
Static Public Member Functions | |
static constexpr bool | is_secure () noexcept |
Indicates that this socket implementation is not secure. |
Class implementing TCP socket functionality for reliable, stream-oriented communication.
This class provides TCP socket functionality, inheriting protectedly from the base qb::io::socket and exposing a TCP-specific interface. It supports connecting to and communicating over TCP/IPv4, TCP/IPv6, and Unix Domain Sockets (if enabled). It is used as the underlying I/O primitive for qb::io::transport::tcp.
|
default |
Default constructor.
Creates an uninitialized TCP socket. Call init() before use.
|
delete |
Deleted copy constructor.
Sockets are not copyable.
|
noexcept |
Constructor from a generic qb::io::socket (move semantics).
sock | A generic qb::io::socket instance, typically already opened with SOCK_STREAM. The state of sock is moved into this tcp::socket. |
Default move assignment operator.
|
noexcept |
Move assignment operator from a generic qb::io::socket.
sock | A generic qb::io::socket to move from. |
|
noexcept |
Initialize (open) the TCP socket.
af | Address family (e.g., AF_INET, AF_INET6, AF_UNIX). Defaults to AF_INET. |
This method calls the base qb::io::socket::open() with SOCK_STREAM type.
|
noexcept |
Bind the socket to a specific local endpoint.
ep | The qb::io::endpoint to bind to. |
|
noexcept |
Bind the socket to an endpoint specified by a URI.
u | The qb::io::uri specifying the local address and port to bind to. |
|
noexcept |
Connect to a remote TCP endpoint.
ep | The qb::io::endpoint of the remote server. |
|
noexcept |
Connect to a remote TCP endpoint specified by a URI.
u | The qb::io::uri of the remote server. |
|
noexcept |
Connect to an IPv4 TCP server.
host | The hostname or IP address string of the server. |
port | The port number of the server. |
|
noexcept |
Connect to an IPv6 TCP server.
host | The hostname or IP address string of the server. |
port | The port number of the server. |
|
noexcept |
Connect to a Unix domain TCP-style socket.
path | The file system path of the Unix domain socket. |
|
noexcept |
Initiate a non-blocking connect to a remote TCP endpoint.
ep | The qb::io::endpoint of the remote server. |
Sets the socket to non-blocking before attempting to connect. The connected() method (or handle_write_ready) should be checked later to confirm connection.
|
inlinenoexcept |
Called after a non-blocking connect attempt succeeds or needs to be finalized.
For TCP, this method typically checks for socket errors to confirm successful connection after n_connect indicated progress. In this base tcp::socket, it's a no-op but can be overridden by derived classes (like ssl::socket for handshake).
|
noexcept |
Initiate a non-blocking connect to a remote TCP endpoint specified by a URI.
u | The qb::io::uri of the remote server. |
|
noexcept |
Initiate a non-blocking connect to an IPv4 TCP server.
host | The hostname or IP address string of the server. |
port | The port number of the server. |
|
noexcept |
Initiate a non-blocking connect to an IPv6 TCP server.
host | The hostname or IP address string of the server. |
port | The port number of the server. |
|
noexcept |
Initiate a non-blocking connect to a Unix domain TCP-style socket.
path | The file system path of the Unix domain socket. |
|
noexcept |
Read data from the connected TCP socket.
dest | Pointer to the buffer where received data will be stored. |
len | Maximum number of bytes to read into the buffer. |
|
noexcept |
Write data to the connected TCP socket.
data | Pointer to the data to be sent. |
size | Number of bytes to send from the data buffer. |
|
noexcept |
Disconnect the TCP socket.
This typically calls qb::io::socket::shutdown() with SD_BOTH and then close().