#include <icy/net/tcpsocket.h>Inherits:
Stream< uv_tcp_t >,SocketSubclassed by:SSLSocket
TCP socket implementation.
| Return | Name | Description |
|---|---|---|
LocalSignal< void(const net::TCPSocket::Ptr &)> | AcceptConnection | Fired when a new client connection is accepted; carries a shared_ptr to the new socket. |
LocalSignal< void(const net::TCPSocket::Ptr &)> AcceptConnectionFired when a new client connection is accepted; carries a shared_ptr to the new socket.
| Return | Name | Description |
|---|---|---|
TCPSocket | Constructs the TCPSocket and initializes the underlying libuv handle. | |
TCPSocket | Deleted constructor. | |
TCPSocket | Deleted constructor. | |
bool | shutdown virtual | Sends a TCP shutdown request; the socket closes after the peer acknowledges. |
void | close virtual | Closes the socket immediately, releasing all associated resources. |
void | connect virtual | Connects to peerAddress using a libuv connect request. On success, calls onConnect(); on failure, calls setUVError(). |
void | connect virtual | Resolves host via DNS (or maps "localhost"), then connects. |
ssize_t | send virtual | Writes len bytes to the connected peer. |
ssize_t | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
ssize_t | send virtual | Writes len bytes; peerAddress is ignored for TCP (connected stream). |
ssize_t | sendOwned virtual | |
void | bind virtual | Binds the socket to address. Resets and reinitializes the handle if the address family changes. |
void | listen virtual | Starts listening for incoming connections with the given backlog. |
void | acceptConnection virtual | Accepts the next pending client connection and fires AcceptConnection. |
bool | setReusePort | Enables SO_REUSEPORT on Linux kernel >= 3.9 for multi-thread load balancing. Must be called after bind(). No-op and returns false on unsupported platforms. |
bool | setNoDelay | Enables or disables TCP_NODELAY (Nagle's algorithm). |
bool | setKeepAlive | Enables or disables TCP keep-alive probes. |
bool | setSimultaneousAccepts | Enables or disables simultaneous accepts on Windows. No-op and returns false on non-Windows platforms. |
void | setMode | Sets the socket mode (ServerSide or ClientSide). |
SocketMode | mode const | Returns the current socket mode. |
void | setError virtual | Sets the socket error; ignores the call if an error is already recorded. Setting an error causes the socket to close. |
const icy::Error & | error virtual const | Returns the current socket error, if any. |
bool | closed virtual const | Returns true if the native socket handle is closed. |
net::Address | address virtual const | Returns the IP address and port number of the socket. A wildcard address is returned if the socket is not connected. |
net::Address | peerAddress virtual const | Returns the IP address and port number of the peer socket. A wildcard address is returned if the socket is not connected. |
net::TransportType | transport virtual const | Returns the TCP transport protocol. |
uv::Loop * | loop virtual const | Returns the event loop associated with this socket. |
void | onConnect virtual | Called by the stream layer when the TCP connection is established. |
void | onRead virtual | Called by the stream layer with raw received bytes; wraps them in a MutableBuffer. |
void | onRecv virtual | Dispatches a received buffer to all socket adapters via onSocketRecv. |
void | onError virtual | Dispatches the error to adapters and closes the socket. |
void | onClose virtual | Dispatches the close event to all socket adapters. |
TCPSocket(uv::Loop * loop)Constructs the TCPSocket and initializes the underlying libuv handle.
loop Event loop to use; defaults to the default loop.TCPSocket(const TCPSocket &) = deleteDeleted constructor.
TCPSocket(TCPSocket &&) = deleteDeleted constructor.
virtual
virtual bool shutdown()Sends a TCP shutdown request; the socket closes after the peer acknowledges.
true if the shutdown request was queued successfully.
virtual
virtual void close()Closes the socket immediately, releasing all associated resources.
virtual
virtual void connect(const net::Address & peerAddress)Connects to peerAddress using a libuv connect request. On success, calls onConnect(); on failure, calls setUVError().
peerAddress The remote address to connect to.virtual
virtual void connect(std::string_view host, uint16_t port)Resolves host via DNS (or maps "localhost"), then connects.
host Hostname or IP address string.
port Destination port.
virtual
virtual ssize_t send(const char * data, size_t len, int flags)Writes len bytes to the connected peer.
data Pointer to the data to send.
len Number of bytes to send.
flags Reserved; currently unused.
Number of bytes sent, or -1 on error.
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags)Sends an owned payload buffer to the connected peer.
virtual
virtual ssize_t send(const char * data, size_t len, const net::Address & peerAddress, int flags)Writes len bytes; peerAddress is ignored for TCP (connected stream).
data Pointer to the data to send.
len Number of bytes to send.
peerAddress Ignored; present for interface conformance.
flags Reserved; currently unused.
Number of bytes sent, or -1 on error.
virtual
virtual ssize_t sendOwned(Buffer && buffer, const net::Address & peerAddress, int flags)virtual
virtual void bind(const net::Address & address, unsigned flags)Binds the socket to address. Resets and reinitializes the handle if the address family changes.
address Local address to bind to.
flags Optional bind flags (e.g. UV_TCP_IPV6ONLY is added automatically for IPv6).
virtual
virtual void listen(int backlog)Starts listening for incoming connections with the given backlog.
backlog Maximum length of the pending connection queue.virtual
virtual void acceptConnection()Accepts the next pending client connection and fires AcceptConnection.
bool setReusePort()Enables SO_REUSEPORT on Linux kernel >= 3.9 for multi-thread load balancing. Must be called after bind(). No-op and returns false on unsupported platforms.
true if the socket option was set successfully.
bool setNoDelay(bool enable)Enables or disables TCP_NODELAY (Nagle's algorithm).
enable true to disable Nagle's algorithm (lower latency).true if the option was set successfully.
bool setKeepAlive(bool enable, int delay)Enables or disables TCP keep-alive probes.
enable true to enable keep-alive.
delay Initial delay in seconds before the first keep-alive probe.
true if the option was set successfully.
bool setSimultaneousAccepts(bool enable)Enables or disables simultaneous accepts on Windows. No-op and returns false on non-Windows platforms.
enable true to enable simultaneous accepts.true if the option was set successfully.
void setMode(SocketMode mode)Sets the socket mode (ServerSide or ClientSide).
mode The mode to assign.const
SocketMode mode() constReturns the current socket mode.
virtual
virtual void setError(const icy::Error & err)Sets the socket error; ignores the call if an error is already recorded. Setting an error causes the socket to close.
err The error to record.virtual const
virtual const icy::Error & error() constReturns the current socket error, if any.
virtual const
virtual bool closed() constReturns true if the native socket handle is closed.
virtual const
virtual net::Address address() constReturns the IP address and port number of the socket. A wildcard address is returned if the socket is not connected.
virtual const
virtual net::Address peerAddress() constReturns the IP address and port number of the peer socket. A wildcard address is returned if the socket is not connected.
virtual const
virtual net::TransportType transport() constReturns the TCP transport protocol.
virtual const
virtual uv::Loop * loop() constReturns the event loop associated with this socket.
virtual
virtual void onConnect()Called by the stream layer when the TCP connection is established.
virtual
virtual void onRead(const char * data, size_t len)Called by the stream layer with raw received bytes; wraps them in a MutableBuffer.
data Pointer to received bytes.
len Number of bytes received.
virtual
virtual void onRecv(const MutableBuffer & buf)Dispatches a received buffer to all socket adapters via onSocketRecv.
buf The buffer containing the received data.virtual
virtual void onError(const icy::Error & error)Dispatches the error to adapters and closes the socket.
error The error that occurred.virtual
virtual void onClose()Dispatches the close event to all socket adapters.
| Return | Name | Description |
|---|---|---|
SocketMode | _mode | |
net::Address | _peerAddress | Cached peer address (avoids syscall per recv) |
SocketMode _modenet::Address _peerAddressCached peer address (avoids syscall per recv)
| Return | Name | Description |
|---|---|---|
void | init virtual | Initializes the underlying socket context. |
void | reset virtual | Resets the socket context for reuse. |
virtual
virtual void init()Initializes the underlying socket context.
virtual
virtual void reset()Resets the socket context for reuse.
std::shared_ptr< TCPSocket > Ptr()std::vector< Ptr > Vec()