|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
Connection-oriented socket for receiving and transmitting ordered, reliable streams of data across the network over ProtocolType::TCP. More...
#include <GREM/networking/Socket.hpp>

Public Member Functions | |
| TCPSocket () noexcept | |
| Construct a closed TCP socket with an invalid socket handle. | |
| TCPSocket (SOCKET handle) noexcept | |
| Construct a TCP socket from a native socket handle. | |
| TCPSocket (BlockingMode mode, const Endpoint &endpoint, std::error_code &errorCode, const TCPSocketOptions &options={}) | |
| Construct a new open TCP socket and establish a TCP connection to the remote socket at the specified address and port. | |
| TCPSocket (BlockingMode mode, const Endpoint &endpoint, const TCPSocketOptions &options={}) | |
| Construct a new open TCP socket and establish a TCP connection to the remote socket at the specified address and port, throwing an exception on failure. | |
| void | connect (BlockingMode mode, const Endpoint &endpoint, std::error_code &errorCode, const TCPSocketOptions &options={}) |
| Replace this socket with a newly created open socket and establish a TCP connection to the remote socket at the specified address and port. | |
| void | connect (BlockingMode mode, const Endpoint &endpoint, const TCPSocketOptions &options={}) |
| Replace this socket with a newly created open socket and establish a TCP connection to the remote socket at the specified address and port, throwing an exception on failure. | |
| void | disconnect (std::error_code &errorCode) |
| Shut down the connection on the socket in the outgoing direction, disallowing further transmissions, and initiate a graceful shutdown of the TCP connection. | |
| void | disconnect () |
| Shut down the connection on the socket in the outgoing direction, disallowing further transmissions, and initiate a graceful shutdown of the TCP connection, throwing an exception on failure. | |
| Optional< size_t > | send (Span< const byte > bytes, MessageFlags flags, std::error_code &errorCode) |
| Appends some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect(). | |
| Optional< size_t > | send (Span< const byte > bytes, MessageFlags flags) |
| Append some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect(), throwing an exception on failure. | |
| GREM_ALWAYS_INLINE Optional< size_t > | send (Span< const byte > bytes, std::error_code &errorCode) |
| Append some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect(), using the default send() flags. | |
| GREM_ALWAYS_INLINE Optional< size_t > | send (Span< const byte > bytes) |
| Append some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect(), using the default send() flags, throwing an exception on failure. | |
| Optional< size_t > | sendTo (const Endpoint &endpoint, Span< const byte > bytes, MessageFlags flags, std::error_code &errorCode) |
| Append some data to the socket's outgoing TCP stream, to be sent to a given remote address. | |
| Optional< size_t > | sendTo (const Endpoint &endpoint, Span< const byte > bytes, MessageFlags flags) |
| Append some data to the socket's outgoing TCP stream, to be sent to a given remote address, throwing an exception on failure. | |
| GREM_ALWAYS_INLINE Optional< size_t > | sendTo (const Endpoint &endpoint, Span< const byte > bytes, std::error_code &errorCode) |
| Append some data to the socket's outgoing TCP stream, to be sent to a given remote address, using the default sendto() flags. | |
| GREM_ALWAYS_INLINE Optional< size_t > | sendTo (const Endpoint &endpoint, Span< const byte > bytes) |
| Append some data to the socket's outgoing TCP stream, to be sent to a given remote address, using the default sendto() flags, throwing an exception on failure. | |
| operator bool () const noexcept | |
| Check if this is a valid open (though not necessarily bound or connected) socket, i.e. if its handle is not equal to INVALID_SOCKET. | |
| void | close (std::error_code &errorCode) noexcept |
| Close the socket and set its handle to INVALID_SOCKET. | |
| void | close () noexcept |
| Close the socket and set its handle to INVALID_SOCKET, ignoring failure. | |
| SOCKET | get () const noexcept |
| Get the native handle of the socket. | |
| Optional< Endpoint > | getLocalEndpoint (std::error_code &errorCode) const |
| Get the local endpoint address and port of the socket using getsockname(). | |
| Endpoint | getLocalEndpoint () const |
| Get the local endpoint address and port of the socket using getsockname(), throwing an exception on failure. | |
| Optional< Endpoint > | getRemoteEndpoint (std::error_code &errorCode) const |
| Get the remote endpoint address and port of the socket using getpeername(). | |
| Endpoint | getRemoteEndpoint () const |
| Get the remote endpoint address and port of the socket using getpeername(), throwing an exception on failure. | |
| Optional< Span< byte > > | receive (Span< byte > buffer, MessageFlags flags, std::error_code &errorCode) |
| Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(). | |
| Optional< Span< byte > > | receive (Span< byte > buffer, MessageFlags flags) |
| Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), throwing an exception on failure. | |
| GREM_ALWAYS_INLINE Optional< Span< byte > > | receive (Span< byte > buffer, std::error_code &errorCode) |
| Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recv() flags. | |
| GREM_ALWAYS_INLINE Optional< Span< byte > > | receive (Span< byte > buffer) |
| Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recv() flags, throwing an exception on failure. | |
| Optional< Pair< Span< byte >, Endpoint > > | receiveFrom (Span< byte > buffer, MessageFlags flags, std::error_code &errorCode) |
| Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(). | |
| Optional< Pair< Span< byte >, Endpoint > > | receiveFrom (Span< byte > buffer, MessageFlags flags) |
| Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), throwing an exception on failure. | |
| GREM_ALWAYS_INLINE Optional< Pair< Span< byte >, Endpoint > > | receiveFrom (Span< byte > buffer, std::error_code &errorCode) |
| Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recvfrom() flags. | |
| GREM_ALWAYS_INLINE Optional< Pair< Span< byte >, Endpoint > > | receiveFrom (Span< byte > buffer) |
| Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recvfrom() flags, throwing an exception on failure. | |
| SOCKET | release () noexcept |
| Relinquish ownership of the socket's native handle. | |
| void | setBlockingMode (BlockingMode newMode, std::error_code &errorCode) |
| Set the blocking mode of the socket. | |
| void | setBlockingMode (BlockingMode newMode) |
| Set the blocking mode of the socket, throwing an exception on failure. | |
| void | setReceiveTimeout (Duration newTimeout, std::error_code &errorCode) |
| Set the receive timeout of the socket. | |
| void | setReceiveTimeout (Duration newTimeout) |
| Set the receive timeout of the socket, throwing an exception on failure. | |
| void | setSendTimeout (Duration newTimeout, std::error_code &errorCode) |
| Set the send timeout of the socket. | |
| void | setSendTimeout (Duration newTimeout) |
| Set the send timeout of the socket, throwing an exception on failure. | |
Connection-oriented socket for receiving and transmitting ordered, reliable streams of data across the network over ProtocolType::TCP.
|
inlinenoexcept |
Construct a closed TCP socket with an invalid socket handle.
|
inlineexplicitnoexcept |
Construct a TCP socket from a native socket handle.
| handle | native socket handle for this socket to adopt. Must either be a valid socket handle of type ProtocolType::TCP (SOCK_STREAM) or be equal to INVALID_SOCKET. |
|
inline |
Construct a new open TCP socket and establish a TCP connection to the remote socket at the specified address and port.
| mode | blocking mode of the new socket. |
| endpoint | remote address, port, etc. to connect to. The address family of the endpoint determines the communication domain to open the socket for. |
| errorCode | error code that is filled in on failure to create/connect the socket, or cleared on success. |
| options | socket options, see TCPSocketOptions. |
|
inline |
Construct a new open TCP socket and establish a TCP connection to the remote socket at the specified address and port, throwing an exception on failure.
| mode | blocking mode of the new socket. |
| endpoint | remote address, port, etc. to connect to. The address family of the endpoint determines the communication domain to open the socket for. |
| options | socket options, see TCPSocketOptions. |
| networking::Error | on failure to create/connect the socket. |
| std::bad_alloc | on allocation failure. |
| void grem::networking::TCPSocket::connect | ( | BlockingMode | mode, |
| const Endpoint & | endpoint, | ||
| std::error_code & | errorCode, | ||
| const TCPSocketOptions & | options = {} ) |
Replace this socket with a newly created open socket and establish a TCP connection to the remote socket at the specified address and port.
| mode | blocking mode of the new socket. |
| endpoint | remote address, port, etc. to connect to. The address family of the endpoint determines the communication domain to open the socket for. |
| errorCode | error code that is filled in on failure to close the old socket or create/connect the new socket, or cleared on success. |
| options | socket options, see TCPSocketOptions. |
|
inline |
Replace this socket with a newly created open socket and establish a TCP connection to the remote socket at the specified address and port, throwing an exception on failure.
| mode | blocking mode of the new socket. |
| endpoint | remote address, port, etc. to connect to. The address family of the endpoint determines the communication domain to open the socket for. |
| options | socket options, see TCPSocketOptions. |
| networking::Error | on failure to close the old socket or create/connect the new socket. |
| std::bad_alloc | on allocation failure. |
|
inline |
Shut down the connection on the socket in the outgoing direction, disallowing further transmissions, and initiate a graceful shutdown of the TCP connection.
| errorCode | error code that is filled in on failure to shut down the connection, or cleared on success. |
|
inline |
Shut down the connection on the socket in the outgoing direction, disallowing further transmissions, and initiate a graceful shutdown of the TCP connection, throwing an exception on failure.
| networking::Error | on failure to shut down the connection. |
| std::bad_alloc | on allocation failure. |
|
inline |
Appends some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect().
| bytes | data to write. |
| flags | bitmask of MSG_... flags to pass to send(), or 0 for no flags. |
| errorCode | error code that is filled in on failure to send data, or cleared on success. |
|
inlinenodiscard |
Append some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect(), throwing an exception on failure.
| bytes | data to write. |
| flags | bitmask of MSG_... flags to pass to send(), or 0 for no flags. |
| networking::Error | on failure to send data. |
| std::bad_alloc | on allocation failure. |
|
inline |
Append some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect(), using the default send() flags.
| bytes | data to write. |
| errorCode | error code that is filled in on failure to send data, or cleared on success. |
|
inlinenodiscard |
Append some data to the socket's outgoing TCP stream, to be sent to the remote address specified through a previous call to connect(), using the default send() flags, throwing an exception on failure.
| bytes | data to write. |
| networking::Error | on failure to send data. |
| std::bad_alloc | on allocation failure. |
|
inline |
Append some data to the socket's outgoing TCP stream, to be sent to a given remote address.
| endpoint | destination address to send the data to. |
| bytes | data to write. |
| flags | bitmask of MSG_... flags to pass to sendto(), or 0 for no flags. |
| errorCode | error code that is filled in on failure to send data, or cleared on success. |
|
inlinenodiscard |
Append some data to the socket's outgoing TCP stream, to be sent to a given remote address, throwing an exception on failure.
| endpoint | destination address to send the data to. |
| bytes | data to write. |
| flags | bitmask of MSG_... flags to pass to sendto(), or 0 for no flags. |
| networking::Error | on failure to send data. |
| std::bad_alloc | on allocation failure. |
|
inline |
Append some data to the socket's outgoing TCP stream, to be sent to a given remote address, using the default sendto() flags.
| endpoint | destination address to send the data to. |
| bytes | data to write. |
| errorCode | error code that is filled in on failure to send data, or cleared on success. |
|
inlinenodiscard |
Append some data to the socket's outgoing TCP stream, to be sent to a given remote address, using the default sendto() flags, throwing an exception on failure.
| endpoint | destination address to send the data to. |
| bytes | data to write. |
| networking::Error | on failure to send data. |
| std::bad_alloc | on allocation failure. |
|
inlineexplicitnoexcept |
Check if this is a valid open (though not necessarily bound or connected) socket, i.e. if its handle is not equal to INVALID_SOCKET.
|
noexcept |
Close the socket and set its handle to INVALID_SOCKET.
| errorCode | error code that is filled in on failure to close the socket, or cleared on success. |
|
inlinenoexcept |
Close the socket and set its handle to INVALID_SOCKET, ignoring failure.
|
inlinenodiscardnoexcept |
Get the native handle of the socket.
|
nodiscard |
Get the local endpoint address and port of the socket using getsockname().
| errorCode | error code that is filled in on failure to get the local endpoint, or cleared on success. |
|
inlinenodiscard |
Get the local endpoint address and port of the socket using getsockname(), throwing an exception on failure.
| networking::Error | on failure to get the local endpoint. |
| std::bad_alloc | on allocation failure. |
|
nodiscard |
Get the remote endpoint address and port of the socket using getpeername().
| errorCode | error code that is filled in on failure to get the remote endpoint, or cleared on success. |
|
inlinenodiscard |
Get the remote endpoint address and port of the socket using getpeername(), throwing an exception on failure.
| networking::Error | on failure to get the remote endpoint. |
| std::bad_alloc | on allocation failure. |
|
nodiscard |
Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect().
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| flags | bitmask of MSG_... flags to pass to recv(), or 0 for no flags. |
| errorCode | error code that is filled in on failure to receive data, or cleared on success. |
|
inlinenodiscard |
Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| flags | bitmask of MSG_... flags to pass to recv(), or 0 for no flags. |
| networking::Error | on failure to receive data. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recv() flags.
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| errorCode | error code that is filled in on failure to receive data, or cleared on success. |
|
inlinenodiscard |
Get some data from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recv() flags, throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| networking::Error | on failure to receive data. |
| std::bad_alloc | on allocation failure. |
|
nodiscard |
Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect().
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| flags | bitmask of MSG_... flags to pass to recvfrom(), or 0 for no flags. |
| errorCode | error code that is filled in on failure to receive data, or cleared on success. |
|
inlinenodiscard |
Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| flags | bitmask of MSG_... flags to pass to recvfrom(), or 0 for no flags. |
| networking::Error | on failure to receive data. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recvfrom() flags.
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| errorCode | error code that is filled in on failure to receive data, or cleared on success. |
|
inlinenodiscard |
Get some data and its associated source address from the socket's incoming data queue, received from the remote address(es) specified through a previous call to bind() or connect(), using the default recvfrom() flags, throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this will consume one datagram from the incoming packet queue. If the full packet does not fit in the given buffer, the remaining data in the consumed packet is discarded.
If the socket is of type ProtocolType::TCP, this will consume available data from the incoming TCP stream, up to the requested number of bytes in the given buffer.
| buffer | writable span to read received data into. The size of the span determines the maximum number of bytes that are attempted to be read. |
| networking::Error | on failure to receive data. |
| std::bad_alloc | on allocation failure. |
|
inlinenoexcept |
Relinquish ownership of the socket's native handle.
This socket will have its handle reset to INVALID_SOCKET without destroying/closing the socket associated with the returned handle.
| void grem::networking::Socket::setBlockingMode | ( | BlockingMode | newMode, |
| std::error_code & | errorCode ) |
Set the blocking mode of the socket.
| newMode | new blocking mode to set, or BlockingMode::UNSPECIFIED to leave the blocking mode unchanged. |
| errorCode | error code that is filled in on failure to set the blocking mode, or cleared on success. |
|
inline |
Set the blocking mode of the socket, throwing an exception on failure.
| newMode | new blocking mode to set, or BlockingMode::UNSPECIFIED to leave the blocking mode unchanged. |
| networking::Error | on failure to set the blocking mode. |
| std::bad_alloc | on allocation failure. |
| void grem::networking::Socket::setReceiveTimeout | ( | Duration | newTimeout, |
| std::error_code & | errorCode ) |
Set the receive timeout of the socket.
| newTimeout | new receive timeout to set. |
| errorCode | error code that is filled in on failure to set the receive timeout, or cleared on success. |
|
inline |
Set the receive timeout of the socket, throwing an exception on failure.
| newTimeout | new receive timeout to set. |
| networking::Error | on failure to set the receive timeout. |
| std::bad_alloc | on allocation failure. |
| void grem::networking::Socket::setSendTimeout | ( | Duration | newTimeout, |
| std::error_code & | errorCode ) |
Set the send timeout of the socket.
| newTimeout | new send timeout to set. |
| errorCode | error code that is filled in on failure to set the send timeout, or cleared on success. |
|
inline |
Set the send timeout of the socket, throwing an exception on failure.
| newTimeout | new send timeout to set. |
| networking::Error | on failure to set the send timeout. |
| std::bad_alloc | on allocation failure. |