4#include "../Foundation/AlignedStorage.h"
5#include "../Foundation/Result.h"
6#include "../Foundation/Span.h"
7#include "../Foundation/StringViewData.h"
8#include "../Foundation/UniqueHandle.h"
14struct SocketDescriptorDefinition;
18struct SocketIPAddress;
33#if SC_PLATFORM_WINDOWS
35struct SC::detail::SocketDescriptorDefinition
38 static Result releaseHandle(Handle& handle);
40 static constexpr Handle Invalid = ~static_cast<Handle>(0);
45struct SC::detail::SocketDescriptorDefinition
48 static Result releaseHandle(Handle& handle);
50 static constexpr Handle Invalid = -1;
104 friend struct SocketIPAddressInternal;
105 [[nodiscard]]
static AddressFamily AddressFamilyFromInt(
int value);
106 [[nodiscard]]
static unsigned char toNative(
AddressFamily family);
107 [[nodiscard]]
static SocketType SocketTypeFromInt(
int value);
108 [[nodiscard]]
static int toNative(
SocketType family);
110 [[nodiscard]]
static ProtocolType ProtocolTypeFromInt(
int value);
158 return formatAddress(buffer);
#define SC_COMPILER_EXPORT
Macro for symbol visibility in non-MSVC compilers.
Definition Compiler.h:78
unsigned short uint16_t
Platform independent (2) bytes unsigned int.
Definition PrimitiveTypes.h:37
unsigned long size_t
Platform independent unsigned size type.
Definition PrimitiveTypes.h:56
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
A buffer of bytes with given alignment.
Definition AlignedStorage.h:29
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
Use a SocketDescriptor as a client (example a TCP or UDP socket client).
Definition Socket.h:67
Low-level OS socket handle.
Definition SocketDescriptor.h:178
Result shutdown(SocketFlags::ShutdownType shutdownType)
Shuts down the socket for reading, writing, or both.
Result isInheritable(bool &value) const
Check if socket is inheritable by child processes.
Result setBlocking(bool value)
Changes the blocking flag for this socket (if IO reads / writes should be blocking or not)
Result setInheritable(bool value)
Changes the inheritable flag for this socket.
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 getAddressFamily(SocketFlags::AddressFamily &addressFamily) const
Get address family (IPV4 / IPV6) of this socket.
Flags for SocketDescriptor (Blocking / Inheritable, IPVx, SocketType)
Definition SocketDescriptor.h:57
SocketType
Sets the socket type, if it's a Datagram (for UDP) or Streaming (for TCP and others)
Definition SocketDescriptor.h:81
@ SocketStream
Sets the socket type as Streaming type (for TCP and others)
Definition SocketDescriptor.h:82
@ SocketDgram
Sets the socket type as Streaming type (for UDP)
Definition SocketDescriptor.h:83
AddressFamily
Sets the address family of an IP Address (IPv4 or IPV6)
Definition SocketDescriptor.h:74
@ AddressFamilyIPV6
IP Address is IPV6.
Definition SocketDescriptor.h:76
@ AddressFamilyIPV4
IP Address is IPV4.
Definition SocketDescriptor.h:75
InheritableType
Sets the socket inheritable behaviour for child processes.
Definition SocketDescriptor.h:67
@ NonInheritable
SocketDescriptor will not be inherited by child processes.
Definition SocketDescriptor.h:68
@ Inheritable
SocketDescriptor will be inherited by child processes.
Definition SocketDescriptor.h:69
ShutdownType
Sets the type of shutdown to perform.
Definition SocketDescriptor.h:95
@ ShutdownBoth
Shuts down the socket for both reading and writing.
Definition SocketDescriptor.h:98
@ ShutdownWrite
Shuts down the socket for writing.
Definition SocketDescriptor.h:97
@ ShutdownRead
Shuts down the socket for reading.
Definition SocketDescriptor.h:96
BlockingType
Sets the socket as blocking / nonblocking mode.
Definition SocketDescriptor.h:60
@ NonBlocking
SocketDescriptor is in non-blocking mode.
Definition SocketDescriptor.h:61
@ Blocking
SocketDescriptor is in blocking mode.
Definition SocketDescriptor.h:62
ProtocolType
Sets the socket protocol type.
Definition SocketDescriptor.h:88
@ ProtocolUdp
The protocol is UDP.
Definition SocketDescriptor.h:90
@ ProtocolTcp
The protocol is TCP.
Definition SocketDescriptor.h:89
Native representation of an IP Address.
Definition SocketDescriptor.h:119
uint16_t getPort() const
Get port of this ip address.
char[MAX_ASCII_STRING_LENGTH] AsciiBuffer
Buffer for storing the ASCII representation of an IP Address.
Definition SocketDescriptor.h:124
AlignedStorage< 28 > handle
Handle to native OS representation of the IP Address.
Definition SocketDescriptor.h:162
static constexpr int MAX_ASCII_STRING_LENGTH
Maximum length of the ASCII representation of an IP Address.
Definition SocketDescriptor.h:121
SocketFlags::AddressFamily getAddressFamily() const
Get Address family of this ip address (IPV4 or IPV6)
uint32_t sizeOfHandle() const
Size of the native IP Address representation.
StringViewData toString(char(&buffer)[N]) const
Returns the text representation of this SocketIPAddress.
Definition SocketDescriptor.h:155
SocketIPAddress(SocketFlags::AddressFamily addressFamily=SocketFlags::AddressFamilyIPV4)
Constructs an ip address from a given family (IPV4 or IPV6)
bool isValid() const
Checks if this is a valid IPV4 or IPV6 address.
Result fromAddressPort(StringViewData interfaceAddress, uint16_t port)
Builds this SocketIPAddress parsing given address string and port.
Use a SocketDescriptor as a Server (example TCP or UDP Socket Server).
Definition Socket.h:26
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
An read-only view over a string (to avoid including Strings library)
Definition StringViewData.h:31
Move only handle that has a special tag value flagging its invalid state.
Definition UniqueHandle.h:67