![]() |
jsocketpp 1.0
A cross-platform C++20 socket library.
|
Public base class for raw socket option access via setsockopt() and getsockopt(). More...
#include <SocketOptions.hpp>

Public Member Functions | |
| SocketOptions ()=delete | |
| Default constructor (deleted) for SocketOptions base class. | |
| SocketOptions (const SOCKET sock) noexcept | |
| Initializes the socket option interface with a specific socket descriptor. | |
| virtual | ~SocketOptions ()=default |
| Virtual destructor for safe polymorphic destruction. | |
| SocketOptions (const SocketOptions &)=delete | |
| Copy constructor (deleted) for SocketOptions. | |
| SocketOptions (SocketOptions &&) noexcept=default | |
| Move constructor for SocketOptions. | |
| SocketOptions & | operator= (const SocketOptions &)=delete |
| Copy assignment operator (deleted) for SocketOptions. | |
| SocketOptions & | operator= (SocketOptions &&) noexcept=default |
| Move assignment operator for SocketOptions. | |
| SOCKET | getSocketFd () const noexcept |
| Retrieves the native socket handle (file descriptor or OS-level handle). | |
| void | setOption (int level, int optName, int value) |
| Sets a low-level socket option on the underlying socket. | |
| void | setOption (int level, int optName, const void *value, socklen_t len) |
| Sets a low-level socket option using a structured or binary value. | |
| int | getOption (int level, int optName) const |
| Retrieves the current value of a low-level socket option. | |
| void | getOption (int level, int optName, void *result, socklen_t *len) const |
| Retrieves a socket option into a structured or binary buffer. | |
| void | setReuseAddress (bool on) |
| Enables or disables the SO_REUSEADDR socket option. | |
| bool | getReuseAddress () const |
| Queries whether the socket is currently configured to allow address reuse. | |
| void | setReceiveBufferSize (std::size_t size) |
| Sets the socket's receive buffer size (SO_RCVBUF). | |
| int | getReceiveBufferSize () const |
| Retrieves the current receive buffer size (SO_RCVBUF) of the socket. | |
| void | setSendBufferSize (std::size_t size) |
| Sets the socket's send buffer size (SO_SNDBUF). | |
| int | getSendBufferSize () const |
| Retrieves the current send buffer size (SO_SNDBUF) of the socket. | |
| void | setSoLinger (bool enable, int seconds) |
| Configures the socket's linger behavior (SO_LINGER) during close. | |
| std::pair< bool, int > | getSoLinger () const |
| Retrieves the current SO_LINGER configuration of the socket. | |
| void | setKeepAlive (bool on) |
| Enables or disables TCP-level keepalive behavior on the socket (SO_KEEPALIVE). | |
| bool | getKeepAlive () const |
| Checks whether TCP-level keepalive (SO_KEEPALIVE) is currently enabled. | |
| void | setSoRecvTimeout (int millis) |
| Sets the socket receive timeout (SO_RCVTIMEO) in milliseconds. | |
| void | setSoSendTimeout (int millis) |
| Sets the socket send timeout (SO_SNDTIMEO) in milliseconds. | |
| int | getSoRecvTimeout () const |
| Retrieves the socket receive timeout (SO_RCVTIMEO) in milliseconds. | |
| int | getSoSendTimeout () const |
| Retrieves the socket send timeout (SO_SNDTIMEO) in milliseconds. | |
| void | setNonBlocking (bool nonBlocking) |
| Enables or disables non-blocking mode on the socket. | |
| bool | getNonBlocking () const |
| Queries whether the socket is currently in non-blocking mode. | |
| void | setTcpNoDelay (bool on) |
| Enables or disables Nagle’s algorithm (TCP_NODELAY) on TCP sockets. | |
| bool | getTcpNoDelay () const |
| Queries whether Nagle's algorithm (TCP_NODELAY) is currently disabled. | |
| void | setBroadcast (bool on) |
| Enables or disables the ability to send UDP broadcast messages. | |
| bool | getBroadcast () const |
| Checks whether the socket is currently allowed to send broadcast messages. | |
| void | setIPv6Only (bool enable) |
| Enables or disables IPV6_V6ONLY mode for IPv6-capable sockets. | |
| bool | getIPv6Only () const |
| Queries whether the IPV6_V6ONLY option is enabled on this socket. | |
| void | setReusePort (const bool enable) |
| Enables or disables the SO_REUSEPORT socket option. | |
| bool | getReusePort () const |
| Checks whether the SO_REUSEPORT option is currently enabled on the socket. | |
| void | setMulticastTTL (int ttl) |
| Set the default multicast hop limit / TTL for this socket. | |
| int | getMulticastTTL () const |
| Get the socket’s default multicast hop limit / TTL. | |
| void | setMulticastLoopback (bool enable) |
| Enable or disable multicast loopback for this socket. | |
| bool | getMulticastLoopback () const |
| Read the socket’s multicast loopback flag. | |
| void | setMulticastInterfaceIPv4 (in_addr addr) |
| Select the outgoing IPv4 interface for multicast. | |
| void | setMulticastInterfaceIPv6 (unsigned int ifindex) |
| Select the outgoing IPv6 interface for multicast. | |
| void | joinGroupIPv4 (in_addr group, in_addr iface) |
| Join an IPv4 any-source multicast (ASM) group on a specific interface. | |
| void | leaveGroupIPv4 (in_addr group, in_addr iface) |
| Leave a previously joined IPv4 multicast group on a specific interface. | |
| void | joinGroupIPv6 (in6_addr group, unsigned int ifindex) |
| Join an IPv6 any-source multicast (ASM) group on a specific interface index. | |
| void | leaveGroupIPv6 (in6_addr group, unsigned int ifindex) |
| Leave a previously joined IPv6 multicast group on a specific interface index. | |
Protected Member Functions | |
| void | setSocketFd (const SOCKET sock) noexcept |
| Updates the socket descriptor used by this object. | |
| virtual bool | isPassiveSocket () const noexcept |
| Indicates whether the socket behaves as a passive (listening) socket. | |
Static Protected Member Functions | |
| static bool | is_ipv4_multicast (const in_addr v4) |
| Test whether an IPv4 address is in the multicast range (224.0.0.0/4). | |
| static bool | is_ipv6_multicast (const in6_addr &v6) |
| Test whether an IPv6 address is in the multicast range (ff00::/8). | |
| static int | detectFamily (SOCKET fd) |
| Determine the address family (AF_INET or AF_INET6) of a socket. | |
Private Attributes | |
| SOCKET | _sockFd = INVALID_SOCKET |
| Underlying socket file descriptor. | |
Public base class for raw socket option access via setsockopt() and getsockopt().
The SocketOptions class provides a unified, cross-platform interface for working with socket-level configuration options (e.g., SO_REUSEADDR, SO_RCVBUF, TCP_NODELAY). It is designed to be inherited by classes that manage socket descriptors, enabling those classes to expose low-level tunables without duplicating boilerplate code.
|
private |
Underlying socket file descriptor.