Net module

net

[Socket]({#ref classicy_1_1net_1_1Socket #}) transports, adapters, and address helpers.

net

Socket transports, adapters, and address helpers.

Classes

NameDescription
AddressRepresents an IPv4 or IPv6 socket address with host and port.
PacketSocketEmitterSocket adapter that emits received data as packets.
SocketBase socket implementation from which all sockets derive.
SocketAdapterAbstract adapter interface for socket send/receive chains.
SocketEmitterSocketAdapter that exposes socket events as signals.
SocketPacketDefault packet type emitted by sockets.
SSLAdapterManages the OpenSSL context and BIO buffers for an SSL socket connection.
SSLContextOpenSSL SSL_CTX wrapper for client and server TLS configuration.
SSLManagerSingleton that owns the default client/server TLS contexts and related callbacks.
SSLSessionCached SSL/TLS session wrapper used for client-side resumption.
SSLSocketSSL socket implementation.
TCPSocketTCP socket implementation.
TransactionRequest/response helper for packet types emitted from a socket.
UDPSocketUDP socket implementation.
VerificationErrorDetailsA utility class for certificate error handling.
PacketInfoProvides information about packets emitted from a socket. See SocketPacket.

Enumerations

NameDescription
TransportTypeTransport protocol identifier used to distinguish socket types at runtime.
SocketModeTransport mode for socket adapters and accepted connections.

TransportType

enum TransportType

Transport protocol identifier used to distinguish socket types at runtime.

ValueDescription
UDPUnreliable datagram protocol.
TCPReliable stream protocol.
SSLTCPTLS-encrypted TCP stream.

SocketMode

enum SocketMode

Transport mode for socket adapters and accepted connections.

ValueDescription
ServerSideServer-side adapter.
ClientSideClient-side adapter.

Functions

ReturnNameDescription
std::shared_ptr< SocketT >makeSocket inlineCreates a socket of type SocketT wrapped in a shared_ptr.
SSLContext::VerificationModeconvertVerificationMode inlineNon-case sensitive conversion of a string to a VerificationMode enum. If verMode is illegal an ArgumentException is thrown.
std::stringconvertCertificateError inlineConverts an SSL certificate handling error code into an error message.
std::stringgetLastError inlineReturns the last error from the error stack.
voidclearErrorStack inlineClears the error stack.
voidgetNetworkInterfaces inlinePopulates hosts with all local network interface addresses.
intgetServerSocketSendBufSizeReturns the current send buffer size for a socket handle, in bytes. Passes val=0 to uv_send_buffer_size, which queries rather than sets the value.
intgetServerSocketRecvBufSizeReturns the current receive buffer size for a socket handle, in bytes. Passes val=0 to uv_recv_buffer_size, which queries rather than sets the value.
intsetServerSocketSendBufSizeSets the send buffer size for a socket handle.
intsetServerSocketRecvBufSizeSets the receive buffer size for a socket handle.

makeSocket

inline

template<class SocketT> inline std::shared_ptr< SocketT > makeSocket(uv::Loop * loop)

Creates a socket of type SocketT wrapped in a shared_ptr.

The socket is automatically destroyed when the last shared_ptr owner releases it.

Parameters

Parameters

  • loop Event loop to associate with the socket; defaults to the default loop.

Returns

A shared_ptr owning the newly created socket.


convertVerificationMode

inline

inline SSLContext::VerificationMode convertVerificationMode(const std::string & vMode)

Non-case sensitive conversion of a string to a VerificationMode enum. If verMode is illegal an ArgumentException is thrown.


convertCertificateError

inline

inline std::string convertCertificateError(long errCode)

Converts an SSL certificate handling error code into an error message.


getLastError

inline

inline std::string getLastError()

Returns the last error from the error stack.


clearErrorStack

inline

inline void clearErrorStack()

Clears the error stack.


getNetworkInterfaces

inline

inline void getNetworkInterfaces(std::vector< net::Address > & hosts)

Populates hosts with all local network interface addresses.

Each entry is an IPv4 address constructed from the interface's address4 field. The results include loopback and any other active interfaces reported by libuv.

Parameters

  • hosts Vector to append the discovered addresses to.

getServerSocketSendBufSize

template<typename T> int getServerSocketSendBufSize(uv::Handle< T > & handle)

Returns the current send buffer size for a socket handle, in bytes. Passes val=0 to uv_send_buffer_size, which queries rather than sets the value.

Parameters

  • T The libuv handle type (e.g. uv_tcp_t, uv_udp_t).

Parameters

  • handle The socket handle to query.

Returns

The send buffer size, or a libuv error code on failure.


getServerSocketRecvBufSize

template<typename T> int getServerSocketRecvBufSize(uv::Handle< T > & handle)

Returns the current receive buffer size for a socket handle, in bytes. Passes val=0 to uv_recv_buffer_size, which queries rather than sets the value.

Parameters

  • T The libuv handle type (e.g. uv_tcp_t, uv_udp_t).

Parameters

  • handle The socket handle to query.

Returns

The receive buffer size, or a libuv error code on failure.


setServerSocketSendBufSize

template<typename T> int setServerSocketSendBufSize(uv::Handle< T > & handle, int size)

Sets the send buffer size for a socket handle.

Parameters

  • T The libuv handle type (e.g. uv_tcp_t, uv_udp_t).

Parameters

  • handle The socket handle to configure.

  • size The desired send buffer size in bytes.

Returns

0 on success, or a libuv error code on failure.


setServerSocketRecvBufSize

template<typename T> int setServerSocketRecvBufSize(uv::Handle< T > & handle, int size)

Sets the receive buffer size for a socket handle.

Parameters

  • T The libuv handle type (e.g. uv_tcp_t, uv_udp_t).

Parameters

  • handle The socket handle to configure.

  • size The desired receive buffer size in bytes.

Returns

0 on success, or a libuv error code on failure.

Variables

ReturnNameDescription
constexpr intMAX_TCP_PACKET_SIZEMaximum size of a single TCP receive buffer, in bytes.
constexpr intMAX_UDP_PACKET_SIZEMaximum size of a single UDP datagram payload, in bytes.

MAX_TCP_PACKET_SIZE

constexpr int MAX_TCP_PACKET_SIZE = 64 * 1024

Maximum size of a single TCP receive buffer, in bytes.


MAX_UDP_PACKET_SIZE

constexpr int MAX_UDP_PACKET_SIZE = 1500

Maximum size of a single UDP datagram payload, in bytes.