4#include "../Foundation/AlignedStorage.h"
5#include "../Foundation/Result.h"
6#include "../Foundation/Span.h"
7#include "../Foundation/UniqueHandle.h"
13struct SocketDescriptorDefinition;
17struct SocketIPAddress;
32#if SC_PLATFORM_WINDOWS
34struct SC::detail::SocketDescriptorDefinition
37 static Result releaseHandle(Handle& handle);
39 static constexpr Handle Invalid = ~static_cast<Handle>(0);
44struct SC::detail::SocketDescriptorDefinition
47 static Result releaseHandle(Handle& handle);
49 static constexpr Handle Invalid = -1;
95 friend struct SocketIPAddressInternal;
96 [[nodiscard]]
static AddressFamily AddressFamilyFromInt(
int value);
97 [[nodiscard]]
static unsigned char toNative(
AddressFamily family);
98 [[nodiscard]]
static SocketType SocketTypeFromInt(
int value);
99 [[nodiscard]]
static int toNative(
SocketType family);
101 [[nodiscard]]
static ProtocolType ProtocolTypeFromInt(
int value);
114 : addressFamily(addressFamily)
#define SC_COMPILER_EXPORT
Macro for symbol visibility in non-MSVC compilers.
Definition: Compiler.h:78
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
unsigned short uint16_t
Platform independent (2) bytes unsigned int.
Definition: PrimitiveTypes.h:37
A buffer of bytes with given alignment.
Definition: AlignedStorage.h:25
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:66
Low-level OS socket handle.
Definition: SocketDescriptor.h:147
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:56
SocketType
Sets the socket type, if it's a Datagram (for UDP) or Streaming (for TCP and others)
Definition: SocketDescriptor.h:80
@ SocketStream
Sets the socket type as Streaming type (for TCP and others)
Definition: SocketDescriptor.h:81
@ SocketDgram
Sets the socket type as Streaming type (for UDP)
Definition: SocketDescriptor.h:82
AddressFamily
Sets the address family of an IP Address (IPv4 or IPV6)
Definition: SocketDescriptor.h:73
@ AddressFamilyIPV6
IP Address is IPV6.
Definition: SocketDescriptor.h:75
@ AddressFamilyIPV4
IP Address is IPV4.
Definition: SocketDescriptor.h:74
InheritableType
Sets the socket inheritable behaviour for child processes.
Definition: SocketDescriptor.h:66
@ NonInheritable
SocketDescriptor will not be inherited by child processes.
Definition: SocketDescriptor.h:67
@ Inheritable
SocketDescriptor will be inherited by child processes.
Definition: SocketDescriptor.h:68
BlockingType
Sets the socket as blocking / nonblocking mode.
Definition: SocketDescriptor.h:59
@ NonBlocking
SocketDescriptor is in non-blocking mode.
Definition: SocketDescriptor.h:60
@ Blocking
SocketDescriptor is in blocking mode.
Definition: SocketDescriptor.h:61
ProtocolType
Sets the socket protocol type.
Definition: SocketDescriptor.h:87
@ ProtocolUdp
The protocol is UDP.
Definition: SocketDescriptor.h:89
@ ProtocolTcp
The protocol is TCP.
Definition: SocketDescriptor.h:88
Native representation of an IP Address.
Definition: SocketDescriptor.h:110
AlignedStorage< 28 > handle
Handle to native OS representation of the IP Address.
Definition: SocketDescriptor.h:131
SocketFlags::AddressFamily getAddressFamily()
Get Address family of this ip address (IPV4 or IPV6)
Definition: SocketDescriptor.h:119
uint32_t sizeOfHandle() const
Size of the native IP Address representation.
SocketIPAddress(SocketFlags::AddressFamily addressFamily=SocketFlags::AddressFamilyIPV4)
Constructs an ip address from a given family (IPV4 or IPV6)
Definition: SocketDescriptor.h:113
Result fromAddressPort(SpanStringView 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:25
An read-only view over an ASCII string (to avoid including Strings library)
Definition: Span.h:249
Move only handle that has a special tag value flagging its invalid state.
Definition: UniqueHandle.h:67