7#include "platform/net/net_address.h"
29 UdpSocket() =
default;
32 UdpSocket(
const UdpSocket& other) =
delete;
33 UdpSocket& operator=(
const UdpSocket& other) =
delete;
35 UdpSocket(UdpSocket && other) =
delete;
36 UdpSocket& operator=(UdpSocket && other) =
delete;
45 [[nodiscard]]
bool open(uint16_t port);
85 bool isOpen()
const {
return m_handle != INVALID; }
91 static constexpr intptr_t INVALID = -1;
102 intptr_t m_handle = INVALID;
104 bool m_readFailed =
false;
105 bool m_oversized =
false;
106 bool m_writeFailed =
false;
void close()
Close it. Safe to call on one that was never opened.
bool open(uint16_t port)
Take a port and start listening on every interface.
bool receive(std::vector< uint8_t > &out, NetAddress &from)
Take the next datagram, if one is waiting.
NetAddress localAddress() const
Loopback and the port this is bound to, including one the system picked for zero.
Definition udp_socket.h:83
static constexpr size_t MAX_DATAGRAM
The largest datagram this will send.
Definition udp_socket.h:26
bool send(const NetAddress &to, const uint8_t *bytes, size_t size)
Send size bytes to to.
Where a datagram came from, or is going to: an IPv4 host and a port.
Definition net_address.h:13