Class Socket#

Inheritance Relationships#

Derived Types#

Class Documentation#

class Socket#

Subclassed by TRAP::Network::TCPListener, TRAP::Network::TCPListenerIPv6, TRAP::Network::TCPSocket, TRAP::Network::TCPSocketIPv6, TRAP::Network::UDPSocket, TRAP::Network::UDPSocketIPv6

Public Types

enum class Status#

Status codes that may be returned by socket functions.

Values:

enumerator Done#
enumerator NotReady#
enumerator Partial#
enumerator Disconnected#
enumerator Error#
enum [anonymous]#

Some special values used by sockets.

Values:

enumerator AnyPort#

Public Functions

constexpr Socket() noexcept = default#

Constructor.

constexpr Socket(Socket&&) noexcept = default#

Move constructor.

Socket &operator=(Socket&&) noexcept = default#

Move assignment operator.

consteval Socket(const Socket&) = delete#

Copy constructor.

consteval Socket &operator=(const Socket&) = delete#

Copy assignment operator.

virtual ~Socket()#

Destructor.

void SetBlocking(bool blocking)#

Set the blocking state of the socket.

In blocking mode, calls will not return until they have completed their task. For example, a call to receive in blocking mode won’t return until some data was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking.

Parameters:

blocking – True to set the socket as blocking, false for non-blocking.

constexpr bool IsBlocking() const noexcept#

Tell whether the socket is in blocking or non-blocking mode.

Returns:

True if the socket is blocking, false otherwise.

Protected Types

enum class Type#

Types of protocols that the socket can use.

Values:

enumerator TCP#
enumerator UDP#

Protected Functions

explicit constexpr Socket(Type type) noexcept#

Constructor.

This constructor can only be accessed by derived classes.

Parameters:

type – Type of the socket (TCP or UDP).

constexpr SocketHandle GetHandle() const noexcept#

Return the internal handle of the socket.

The returned handle may be invalid if the socket was not created yet (or already destroyed). This function can only be accessed by derived classes.

Returns:

The internal (OS-specific) handle of the socket.

void CreateIPv4()#

Create the internal representation of the socket.

This function can only be accessed by derived classes.

void CreateIPv6()#

Create the internal representation of the socket.

This function can only be accessed by derived classes.

void Create(SocketHandle handle)#

Create the internal representation of the socket from a socket handle.

This function can only be accessed by derived classes.

Parameters:

handle – OS-specific handle of the socket to wrap.

void Close()#

Close the socket gracefully.

This function can only be accessed by derived classes.