#include <udp_socket.hpp>
|
| UdpSocket (std::shared_ptr< NetworkConfig > config) noexcept |
|
| UdpSocket (std::shared_ptr< NetworkConfig > config, IOMode mode) noexcept |
|
| UdpSocket (UdpSocket &&socket) noexcept |
|
UdpSocket & | operator= (UdpSocket &&socket) noexcept |
|
std::size_t | send (const EndpointType &endpoint, std::string_view message) |
|
std::size_t | send (std::string_view hostname, port_type port, std::string_view message) |
|
bool | send_async (const EndpointType &endpoint, std::string_view message, SendCompletion &&callback) |
|
bool | send_async (std::string_view hostname, port_type port, std::string_view message, SendCompletion &&callback) |
|
std::string | receive () |
|
bool | receive_async (ReceiveCompletion &&callback) |
|
void | close () |
|
socket_type | handle () const |
|
bool | is_open () const |
|
socket_type | handle () const |
|
std::uint64_t | socket_id () const |
|
bool | set_io_mode (fly::net::IOMode mode) |
|
fly::net::IOMode | io_mode () const |
|
std::optional< EndpointType > | local_endpoint () const |
|
void | close () |
|
bool | bind (const EndpointType &endpoint, BindMode mode) const |
|
bool | bind (std::string_view hostname, port_type port, BindMode mode) const |
|
template<IPEndpoint EndpointType>
class fly::net::UdpSocket< EndpointType >
Class to represent a connectionless datagram network socket.
- Author
- Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
- Version
- February 13, 2021
◆ UdpSocket() [1/3]
template<IPEndpoint EndpointType>
Constructor. Open the socket in a synchronous IO processing mode.
- Parameters
-
config | Reference to network configuration. |
◆ UdpSocket() [2/3]
template<IPEndpoint EndpointType>
Constructor. Open the socket in the provided IO processing mode.
- Parameters
-
config | Reference to network configuration. |
mode | IO processing mode to apply to the socket. |
◆ UdpSocket() [3/3]
template<IPEndpoint EndpointType>
Move constructor. The provided socket is left in an invalid state.
- Parameters
-
socket | The socket instance to move. |
◆ close()
template<IPEndpoint EndpointType>
If this socket is valid, close this socket.
◆ handle()
template<IPEndpoint EndpointType>
- Returns
- This socket's native handle.
◆ hostname_to_address()
template<IPEndpoint EndpointType>
Convert a hostname or IP address string to an IP address.
- Parameters
-
hostname | The hostname or IP address string to convert. |
- Returns
- If successful, the created IP address. Otherwise, an uninitialized value.
◆ operator=()
template<IPEndpoint EndpointType>
Move assignment operator. The provided socket is left in an invalid state.
- Parameters
-
socket | The socket instance to move. |
- Returns
- A reference to this socket.
◆ receive()
template<IPEndpoint EndpointType>
Receive a message from an unspecified remote endpoint. If an error occurs on the socket, the socket will be closed.
- Returns
- The message received.
◆ receive_async()
template<IPEndpoint EndpointType>
Asynchronously receive a message from an unspecified remote endpoint. May only be used if this socket was created through a socket service.
Upon completion, the provided callback will be invoked with the message received. If an error occurs on the socket, the callback will still be invoked with any message partially received, but the socket will also be closed before the invocation.
- Parameters
-
callback | The callback to invoke when the operation has completed. |
- Returns
- True if the socket service and the provided callback are valid.
◆ send() [1/2]
template<IPEndpoint EndpointType>
size_t fly::net::UdpSocket< EndpointType >::send |
( |
const EndpointType & |
endpoint, |
|
|
std::string_view |
message |
|
) |
| |
Transmit a message to a specific remote endpoint. If an error occurs on the socket, the socket will be closed.
- Parameters
-
endpoint | The remote endpoint to transmit to. |
message | The message to transmit. |
- Returns
- The number of bytes transmitted.
◆ send() [2/2]
template<IPEndpoint EndpointType>
size_t fly::net::UdpSocket< EndpointType >::send |
( |
std::string_view |
hostname, |
|
|
port_type |
port, |
|
|
std::string_view |
message |
|
) |
| |
Transmit a message to a specific remote endpoint. If an error occurs on the socket, the socket will be closed.
- Parameters
-
hostname | The hostname or IP address string to transmit to. |
port | The port to transmit to. |
message | The message to transmit. |
- Returns
- The number of bytes transmitted.
◆ send_async() [1/2]
template<IPEndpoint EndpointType>
bool fly::net::UdpSocket< EndpointType >::send_async |
( |
const EndpointType & |
endpoint, |
|
|
std::string_view |
message, |
|
|
SendCompletion && |
callback |
|
) |
| |
Asynchronously transmit a message to a specific remote endpoint. May only be used if this socket was created through a socket service.
Upon completion, the provided callback will be invoked with the number of bytes that were transmitted. If an error occurs on the socket, the callback will still be invoked with the number of bytes successfully transmitted, but the socket will also be closed before the invocation.
- Parameters
-
endpoint | The remote endpoint to transmit to. |
message | The message to transmit. |
callback | The callback to invoke when the operation has completed. |
- Returns
- True if the socket service and the provided callback are valid.
◆ send_async() [2/2]
template<IPEndpoint EndpointType>
bool fly::net::UdpSocket< EndpointType >::send_async |
( |
std::string_view |
hostname, |
|
|
port_type |
port, |
|
|
std::string_view |
message, |
|
|
SendCompletion && |
callback |
|
) |
| |
Asynchronously transmit a message to a specific remote endpoint. May only be used if this socket was created through a socket service.
Upon completion, the provided callback will be invoked with the number of bytes that were transmitted. If an error occurs on the socket, the callback will still be invoked with the number of bytes successfully transmitted, but the socket will also be closed before the invocation.
- Parameters
-
hostname | The hostname or IP address string to transmit to. |
port | The port to transmit to. |
message | The message to transmit. |
callback | The callback to invoke when the operation has completed. |
- Returns
- True if the socket service and the provided callback are valid.
The documentation for this class was generated from the following files: