|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
Connectionless socket for receiving and transmitting unordered, unreliable datagrams across the network over ProtocolType::UDP. More...
#include <GREM/networking/Socket.hpp>

Public Member Functions | |
| UDPSocket () noexcept | |
| Construct a closed UDP socket with an invalid socket handle. | |
| UDPSocket (SOCKET handle) noexcept | |
| Construct a UDP socket from a native socket handle. | |
| UDPSocket (BlockingMode mode, const Endpoint &endpoint, std::error_code &errorCode, const UDPSocketOptions &options={}) | |
| Construct a new open UDP socket bound to a specific local port, and set the remote address(es) to receive packets from on that port. | |
| UDPSocket (BlockingMode mode, const Endpoint &endpoint, const UDPSocketOptions &options={}) | |
| Construct a new open UDP socket bound to a specific local port, and set the remote address(es) to receive packets from on that port, throwing an exception on failure. | |
| void | bind (BlockingMode mode, const Endpoint &endpoint, std::error_code &errorCode, const UDPSocketOptions &options={}) |
| Replace this socket with a newly created open socket bound to a specific local port, and set the remote address(es) to receive packets from on that port. | |
| void | bind (BlockingMode mode, const Endpoint &endpoint, const UDPSocketOptions &options={}) |
| Replace this socket with a newly created open socket bound to a specific local port, and set the remote address(es) to receive packets from on that port, 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< 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. | |
| Optional< size_t > | sendTo (const Endpoint &endpoint, Span< const byte > bytes, MessageFlags flags, std::error_code &errorCode) |
| Write some data to the socket's outgoing data queue, to be sent to a given remote address. | |
| Optional< size_t > | sendTo (const Endpoint &endpoint, Span< const byte > bytes, MessageFlags flags) |
| Write some data to the socket's outgoing data queue, 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) |
| Write some data to the socket's outgoing data queue, 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) |
| Write some data to the socket's outgoing data queue, to be sent to a given remote address, using the default sendto() flags, throwing an exception on failure. | |
| 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. | |
Connectionless socket for receiving and transmitting unordered, unreliable datagrams across the network over ProtocolType::UDP.
|
inlinenoexcept |
Construct a closed UDP socket with an invalid socket handle.
|
inlineexplicitnoexcept |
Construct a UDP 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::UDP (SOCK_DGRAM) or equal to INVALID_SOCKET. |
|
inline |
Construct a new open UDP socket bound to a specific local port, and set the remote address(es) to receive packets from on that port.
| mode | blocking mode of the new socket. |
| endpoint | remote address(es) to receive from and local port to bind the socket 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/bind the socket, or cleared on success. |
| options | socket options, see UDPSocketOptions. |
|
inline |
Construct a new open UDP socket bound to a specific local port, and set the remote address(es) to receive packets from on that port, throwing an exception on failure.
| mode | blocking mode of the new socket. |
| endpoint | remote address(es) to receive from and local port to bind the socket to. The address family of the endpoint determines the communication domain to open the socket for. |
| options | socket options, see UDPSocketOptions. |
| networking::Error | on failure to create/bind the socket. |
| std::bad_alloc | on allocation failure. |
|
inline |
Replace this socket with a newly created open socket bound to a specific local port, and set the remote address(es) to receive packets from on that port.
| mode | blocking mode of the new socket. |
| endpoint | remote address(es) to receive from and local port to bind the socket 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/bind the new socket, or cleared on success. |
| options | socket options, see UDPSocketOptions. |
|
inline |
Replace this socket with a newly created open socket bound to a specific local port, and set the remote address(es) to receive packets from on that port, throwing an exception on failure.
| mode | blocking mode of the new socket. |
| endpoint | remote address(es) to receive from and local port to bind the socket to. The address family of the endpoint determines the communication domain to open the socket for. |
| options | socket options, see UDPSocketOptions. |
| networking::Error | on failure to close the old socket or create/bind the new socket. |
| 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 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.
| Optional< size_t > grem::networking::Socket::sendTo | ( | const Endpoint & | endpoint, |
| Span< const byte > | bytes, | ||
| MessageFlags | flags, | ||
| std::error_code & | errorCode ) |
Write some data to the socket's outgoing data queue, to be sent to a given remote address.
If the socket is of type ProtocolType::UDP, this will produce one datagram for the outgoing packet queue.
If the socket is of type ProtocolType::TCP, this will append data to the outgoing TCP stream.
| 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 |
Write some data to the socket's outgoing data queue, to be sent to a given remote address, throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this will produce one datagram for the outgoing packet queue.
If the socket is of type ProtocolType::TCP, this will append data to the outgoing TCP stream.
| 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 |
Write some data to the socket's outgoing data queue, to be sent to a given remote address, using the default sendto() flags.
If the socket is of type ProtocolType::UDP, this will produce one datagram for the outgoing packet queue.
If the socket is of type ProtocolType::TCP, this will append data to the outgoing TCP stream.
| 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 |
Write some data to the socket's outgoing data queue, to be sent to a given remote address, using the default sendto() flags, throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this will produce one datagram for the outgoing packet queue.
If the socket is of type ProtocolType::TCP, this will append data to the outgoing TCP stream.
| 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. |
| 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. |