Low-level OS socket handle. More...
#include <Socket.h>
Public Member Functions | |
| Result | create (SocketFlags::AddressFamily addressFamily, SocketFlags::SocketType socketType=SocketFlags::SocketStream, SocketFlags::ProtocolType protocol=SocketFlags::ProtocolTcp, SocketFlags::BlockingType blocking=SocketFlags::Blocking, SocketFlags::InheritableType inheritable=SocketFlags::NonInheritable) |
| Creates a new SocketDescriptor Descriptor of given family, type, protocol. | |
| Result | isInheritable (bool &value) const |
| Check if socket is inheritable by child processes. | |
| Result | setInheritable (bool value) |
| Changes the inheritable flag for this socket. | |
| Result | setBlocking (bool value) |
| Changes the blocking flag for this socket (if IO reads / writes should be blocking or not) | |
| Result | getAddressFamily (SocketFlags::AddressFamily &addressFamily) const |
| Get the address family of this socket. | |
| Result | shutdown (SocketFlags::ShutdownType shutdownType) |
| Shuts down the socket for reading, writing, or both. | |
| Result | setTcpNoDelay (bool tcpNoDelay) |
| Disables Nagle's algorithm for low-latency communication. | |
| Result | setBroadcast (bool enableBroadcast) |
| Enables or disables broadcast on this socket (for UDP) | |
| Result | joinMulticastGroup (const SocketIPAddress &multicastAddress, const SocketIPAddress &interfaceAddress) |
| Joins an IPv4 or IPv6 multicast group on a specific interface. | |
| Result | leaveMulticastGroup (const SocketIPAddress &multicastAddress, const SocketIPAddress &interfaceAddress) |
| Leaves a previously joined IPv4 or IPv6 multicast group on a specific interface. | |
| Result | setMulticastLoopback (SocketFlags::AddressFamily addressFamily, bool enableLoopback) |
| Controls whether multicast traffic is sent back to the local host. | |
| Result | setMulticastHops (SocketFlags::AddressFamily addressFamily, int hops) |
| Specifies the default TTL or hop limit for outgoing multicast datagrams. | |
| Result | setMulticastOutboundInterface (const SocketIPAddress &interfaceAddress) |
| Specifies the default local network interface for outgoing multicast datagrams. | |
| Result | sendTo (Span< const char > data, const SocketAddress &destination) |
| Sends a datagram to the given destination address. | |
| Result | sendTo (Span< const char > data, const SocketIPAddress &destination) |
| IP-address compatibility overload for sendTo. | |
| Result | receiveFrom (Span< char > buffer, Span< char > &receivedData, SocketAddress &sourceAddress) |
| Receives a datagram, reporting its source address. | |
| Result | receiveFrom (Span< char > buffer, Span< char > &receivedData, SocketIPAddress &sourceAddress) |
| IP-address compatibility overload for receiveFrom. | |
Low-level OS socket handle.
It also allow querying inheritability and changing it (and blocking mode)
Example (extracted from unit test):
| Result SC::SocketDescriptor::create | ( | SocketFlags::AddressFamily | addressFamily, |
| SocketFlags::SocketType | socketType = SocketFlags::SocketStream, | ||
| SocketFlags::ProtocolType | protocol = SocketFlags::ProtocolTcp, | ||
| SocketFlags::BlockingType | blocking = SocketFlags::Blocking, | ||
| SocketFlags::InheritableType | inheritable = SocketFlags::NonInheritable ) |
Creates a new SocketDescriptor Descriptor of given family, type, protocol.
| addressFamily | Address family (IPv4, IPv6, or Unix-domain) |
| socketType | SocketDescriptor type (Stream or Dgram) |
| protocol | Protocol (TCP, UDP, or the family/type default) |
| blocking | If the socket should be created in blocking mode |
| inheritable | If the socket should be inheritable by child processes |
| Result SC::SocketDescriptor::getAddressFamily | ( | SocketFlags::AddressFamily & | addressFamily | ) | const |
Get the address family of this socket.
| [out] | addressFamily | The address family of this socket (if Result is valid) |
| Result SC::SocketDescriptor::isInheritable | ( | bool & | value | ) | const |
Check if socket is inheritable by child processes.
| [out] | value | if set to true indicates that this socket is inheritable by child processes |
| Result SC::SocketDescriptor::joinMulticastGroup | ( | const SocketIPAddress & | multicastAddress, |
| const SocketIPAddress & | interfaceAddress ) |
Joins an IPv4 or IPv6 multicast group on a specific interface.
| multicastAddress | The multicast group address to join |
| interfaceAddress | The local interface address to join on |
| Result SC::SocketDescriptor::leaveMulticastGroup | ( | const SocketIPAddress & | multicastAddress, |
| const SocketIPAddress & | interfaceAddress ) |
Leaves a previously joined IPv4 or IPv6 multicast group on a specific interface.
| multicastAddress | The multicast group address to leave |
| interfaceAddress | The local interface address to leave from |
| Result SC::SocketDescriptor::receiveFrom | ( | Span< char > | buffer, |
| Span< char > & | receivedData, | ||
| SocketAddress & | sourceAddress ) |
Receives a datagram, reporting its source address.
| [in,out] | buffer | Span of memory that will receive the datagram and may be modified on truncation |
| [out] | receivedData | A sub-Span of buffer containing the received bytes; unchanged on failure |
| [out] | sourceAddress | The source address; unchanged on failure |
buffer may contain a truncated prefix | Result SC::SocketDescriptor::receiveFrom | ( | Span< char > | buffer, |
| Span< char > & | receivedData, | ||
| SocketIPAddress & | sourceAddress ) |
IP-address compatibility overload for receiveFrom.
| Result SC::SocketDescriptor::sendTo | ( | Span< const char > | data, |
| const SocketAddress & | destination ) |
Sends a datagram to the given destination address.
| data | Bytes to send as a single datagram; the whole span must be sent for success |
| destination | The destination address of the datagram |
| Result SC::SocketDescriptor::sendTo | ( | Span< const char > | data, |
| const SocketIPAddress & | destination ) |
IP-address compatibility overload for sendTo.
| Result SC::SocketDescriptor::setBlocking | ( | bool | value | ) |
Changes the blocking flag for this socket (if IO reads / writes should be blocking or not)
| value | true if this socket should be made blocking, false for non-blocking |
| Result SC::SocketDescriptor::setBroadcast | ( | bool | enableBroadcast | ) |
Enables or disables broadcast on this socket (for UDP)
| enableBroadcast | true to enable broadcast (set SO_BROADCAST), false to disable |
| Result SC::SocketDescriptor::setInheritable | ( | bool | value | ) |
Changes the inheritable flag for this socket.
| value | true if this socket should be made inheritable, false for non-inheritable |
| Result SC::SocketDescriptor::setMulticastHops | ( | SocketFlags::AddressFamily | addressFamily, |
| int | hops ) |
Specifies the default TTL or hop limit for outgoing multicast datagrams.
| addressFamily | Address family of the socket |
| hops | The hop limit (0-255) |
| Result SC::SocketDescriptor::setMulticastLoopback | ( | SocketFlags::AddressFamily | addressFamily, |
| bool | enableLoopback ) |
Controls whether multicast traffic is sent back to the local host.
| addressFamily | Address family of the socket |
| enableLoopback | true to enable multicast loopback, false to disable |
| Result SC::SocketDescriptor::setMulticastOutboundInterface | ( | const SocketIPAddress & | interfaceAddress | ) |
Specifies the default local network interface for outgoing multicast datagrams.
| interfaceAddress | The local interface address |
| Result SC::SocketDescriptor::setTcpNoDelay | ( | bool | tcpNoDelay | ) |
Disables Nagle's algorithm for low-latency communication.
| tcpNoDelay | true to disable Nagle's algorithm (set TCP_NODELAY), false to enable it |
| Result SC::SocketDescriptor::shutdown | ( | SocketFlags::ShutdownType | shutdownType | ) |
Shuts down the socket for reading, writing, or both.
| shutdownType | The type of shutdown to perform |