|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
Generic socket handle/file descriptor for receiving and transmitting data across the network. More...
#include <GREM/networking/Socket.hpp>

Public Member Functions | |
| Socket () noexcept | |
| Construct a closed socket with an invalid socket handle. | |
| Socket (SOCKET handle) noexcept | |
| Construct a socket from a native socket handle. | |
| Socket (AddressFamily domain, ProtocolType type, std::error_code &errorCode) | |
| Construct a new open socket. | |
| Socket (AddressFamily domain, ProtocolType type) | |
| Construct a new open socket, 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 | release () noexcept |
| Relinquish ownership of the socket's native handle. | |
| void | open (AddressFamily domain, ProtocolType type, std::error_code &errorCode) |
| Replace this socket with a newly created open socket. | |
| void | open (AddressFamily domain, ProtocolType type) |
| Replace this socket with a newly created open socket, 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. | |
| void | connect (const Endpoint &endpoint, std::error_code &errorCode) |
| Initiate a connection on the socket. | |
| void | connect (const Endpoint &endpoint) |
| Initiate a connection on the socket, throwing an exception on failure. | |
| void | bind (const Endpoint &endpoint, std::error_code &errorCode) |
| Assign an address to the socket. | |
| void | bind (const Endpoint &endpoint) |
| Assign an address to the socket, throwing an exception on failure. | |
| void | shutdown (ShutdownType how, std::error_code &errorCode) |
| Shut down the connection on the socket in the specified direction(s), disallowing further receptions and/or transmissions. | |
| void | shutdown (ShutdownType how) |
| Shut down the connection on the socket in the specified direction(s), disallowing further receptions and/or transmissions, throwing an exception on failure. | |
| 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. | |
| void | listen (size_t listenQueueBacklogSize, std::error_code &errorCode) |
| Start accepting incoming TCP connections on the port that the socket is currently bound to, from the remote address(es) that were specified through a previous call to bind(). | |
| void | listen (size_t listenQueueBacklogSize) |
| Start accepting incoming TCP connections on the port that the socket is currently bound to, from the remote address(es) that were specified through a previous call to bind(), throwing an exception on failure. | |
| Optional< Socket > | accept (std::error_code &errorCode) |
| Accept a single incoming TCP connection from the socket's listen queue that was previously set up by a call to listen(). | |
| Optional< Socket > | accept () |
| Accept a single incoming TCP connection from the socket's listen queue that was previously set up by a call to listen(), 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. | |
| Optional< size_t > | send (Span< const byte > bytes, MessageFlags flags, std::error_code &errorCode) |
| Write some data to the socket's outgoing data queue, to be sent to the remote address specified through a previous call to connect(). | |
| Optional< size_t > | send (Span< const byte > bytes, MessageFlags flags) |
| Write some data to the socket's outgoing data queue, 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) |
| Write some data to the socket's outgoing data queue, 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) |
| Write some data to the socket's outgoing data queue, 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) |
| 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 | awaitReadable (Duration timeout, std::error_code &errorCode) |
| Wait for the socket to have incoming data available to be read. | |
| void | awaitReadable (Duration timeout) |
| Wait for the socket to have incoming data available to be read, throwing an exception on failure or timeout. | |
| void | awaitWritable (Duration timeout, std::error_code &errorCode) |
| Wait for the socket to become ready to write outgoing data to. | |
| void | awaitWritable (Duration timeout) |
| Wait for the socket to become ready to write outgoing data to, throwing an exception on failure or timeout. | |
| SOCKET | get () const noexcept |
| Get the native handle of the socket. | |
Static Public Attributes | |
| static constexpr size_t | MAX_LISTEN_QUEUE_BACKLOG_SIZE = SOMAXCONN |
| Maximum listenQueueBacklogSize value that can be passed to listen(). | |
Generic socket handle/file descriptor for receiving and transmitting data across the network.
|
inlinenoexcept |
Construct a closed socket with an invalid socket handle.
|
inlineexplicitnoexcept |
Construct a socket from a native socket handle.
| handle | native socket handle for this socket to adopt. Must either be a valid socket handle or be equal to INVALID_SOCKET. |
|
inline |
Construct a new open socket.
| domain | address family of the communication domain to open the socket for. |
| type | communication semantics of the socket. |
| errorCode | error code that is filled in on failure to create the socket, or cleared on success. |
|
inline |
Construct a new open socket, throwing an exception on failure.
| domain | address family of the communication domain to open the socket for. |
| type | communication semantics of the socket. |
| networking::Error | on failure to create the 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.
|
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::open | ( | AddressFamily | domain, |
| ProtocolType | type, | ||
| std::error_code & | errorCode ) |
Replace this socket with a newly created open socket.
| domain | address family of the communication domain to open the socket for. |
| type | communication semantics of the socket. |
| errorCode | error code that is filled in on failure to close the old socket or create the new socket, or cleared on success. |
|
inline |
Replace this socket with a newly created open socket, throwing an exception on failure.
| domain | address family of the communication domain to open the socket for. |
| type | communication semantics of the socket. |
| networking::Error | on failure to close the old socket or create the new socket. |
| 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. |
| void grem::networking::Socket::connect | ( | const Endpoint & | endpoint, |
| std::error_code & | errorCode ) |
Initiate a connection on the socket.
If the socket is of type ProtocolType::UDP, this sets the address to which packets are sent by default.
If the socket is of type ProtocolType::TCP, it attempts to establish a TCP connection to the remote socket at the specified address.
| endpoint | remote address, port, etc. to connect to. |
| errorCode | error code that is filled in on failure to connect the socket, or cleared on success. |
|
inline |
Initiate a connection on the socket, throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this sets the address and port to which packets are sent by default.
If the socket is of type ProtocolType::TCP, it attempts to establish a TCP connection to the remote socket at the specified address and port.
| endpoint | remote address, port, etc. to connect to. |
| networking::Error | on failure to connect the socket. |
| std::bad_alloc | on allocation failure. |
| void grem::networking::Socket::bind | ( | const Endpoint & | endpoint, |
| std::error_code & | errorCode ) |
Assign an address to the socket.
If the socket is of type ProtocolType::UDP, this binds the socket to the specified local port and sets the remote address(es) to receive packets from on that port.
If the socket is of type ProtocolType::TCP, this binds the socket to the specified local port and makes it possible to listen() for incoming connections from the specified remote address(es) on that port.
| endpoint | remote address(es) to receive from and local port to bind the socket to. |
| errorCode | error code that is filled in on failure to bind the socket, or cleared on success. |
|
inline |
Assign an address to the socket, throwing an exception on failure.
If the socket is of type ProtocolType::UDP, this binds the socket to the specified local port and sets the remote address(es) to receive packets from on that port.
If the socket is of type ProtocolType::TCP, this binds the socket to the specified local port and makes it possible to listen() for incoming connections from the specified remote address(es) on that port.
| endpoint | remote address(es) to receive from and local port to bind the socket to. |
| networking::Error | on failure to bind the socket. |
| std::bad_alloc | on allocation failure. |
| void grem::networking::Socket::shutdown | ( | ShutdownType | how, |
| std::error_code & | errorCode ) |
Shut down the connection on the socket in the specified direction(s), disallowing further receptions and/or transmissions.
| how | direction(s) in which to shut down the 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 specified direction(s), disallowing further receptions and/or transmissions, throwing an exception on failure.
| how | direction(s) in which to shut down the connection. |
| networking::Error | on failure to shut down the connection. |
| std::bad_alloc | on allocation failure. |
|
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. |
| void grem::networking::Socket::listen | ( | size_t | listenQueueBacklogSize, |
| std::error_code & | errorCode ) |
Start accepting incoming TCP connections on the port that the socket is currently bound to, from the remote address(es) that were specified through a previous call to bind().
| listenQueueBacklogSize | maximum number of incoming connections to allow to be queued up between calls to accept(). The value will be clamped between 0 and Socket::MAX_LISTEN_QUEUE_BACKLOG_SIZE (inclusive). A value of 0 is interpreted as a shorthand for Socket::MAX_LISTEN_QUEUE_BACKLOG_SIZE. |
| errorCode | error code that is filled in on failure to start listening, or cleared on success. |
|
inline |
Start accepting incoming TCP connections on the port that the socket is currently bound to, from the remote address(es) that were specified through a previous call to bind(), throwing an exception on failure.
| listenQueueBacklogSize | maximum number of incoming connections to allow to be queued up between calls to accept(). The value will be clamped between 0 and Socket::MAX_LISTEN_QUEUE_BACKLOG_SIZE (inclusive). A value of 0 is interpreted as a shorthand for Socket::MAX_LISTEN_QUEUE_BACKLOG_SIZE. |
| networking::Error | on failure to start listening. |
| std::bad_alloc | on allocation failure. |
Accept a single incoming TCP connection from the socket's listen queue that was previously set up by a call to listen().
| errorCode | error code that is filled in on failure to accept a connection, or cleared on success. |
Accept a single incoming TCP connection from the socket's listen queue that was previously set up by a call to listen(), throwing an exception on failure.
| networking::Error | on failure to accept a connection. |
| 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. |
| Optional< size_t > grem::networking::Socket::send | ( | Span< const byte > | bytes, |
| MessageFlags | flags, | ||
| std::error_code & | errorCode ) |
Write some data to the socket's outgoing data queue, to be sent to the remote address specified through a previous call to connect().
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.
| 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 |
Write some data to the socket's outgoing data queue, to be sent to the remote address specified through a previous call to connect(), 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.
| 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 |
Write some data to the socket's outgoing data queue, to be sent to the remote address specified through a previous call to connect(), using the default send() 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.
| 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 the remote address specified through a previous call to connect(), using the default send() 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.
| bytes | data to write. |
| networking::Error | on failure to send data. |
| std::bad_alloc | on allocation failure. |
| 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::awaitReadable | ( | Duration | timeout, |
| std::error_code & | errorCode ) |
Wait for the socket to have incoming data available to be read.
| timeout | maximum duration of time to wait for. Must be non-negative. |
| errorCode | error code that is filled in on failure, or cleared on success. |
|
inline |
Wait for the socket to have incoming data available to be read, throwing an exception on failure or timeout.
| timeout | maximum duration of time to wait for. Must be non-negative. |
| networking::Error | on failure to await, or timeout. |
| std::bad_alloc | on allocation failure. |
| void grem::networking::Socket::awaitWritable | ( | Duration | timeout, |
| std::error_code & | errorCode ) |
Wait for the socket to become ready to write outgoing data to.
| timeout | maximum duration of time to wait for. Must be non-negative. |
| errorCode | error code that is filled in on failure, or cleared on success. |
|
inline |
Wait for the socket to become ready to write outgoing data to, throwing an exception on failure or timeout.
| timeout | maximum duration of time to wait for. Must be non-negative. |
| networking::Error | on failure to await, or timeout. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscardnoexcept |
Get the native handle of the socket.
|
staticconstexpr |
Maximum listenQueueBacklogSize value that can be passed to listen().