33#include <SDL3/SDL_stdinc.h>
35#include <SDL3_net/SDL_net.h>
50 NET_Address*
addr =
nullptr;
63 addr = other.
addr ? NET_RefAddress(other.
addr) :
nullptr;
89 NET_UnrefAddress(
addr);
121 bool open(
const char* bindAddr, Uint16 port);
124 void close() noexcept;
191 [[nodiscard]] uint16_t
localPort() const noexcept;
uint16_t localPort() const noexcept
Get the local port this socket is bound to.
Definition UdpEndpoint.cpp:219
NET_DatagramSocket * socket_
Definition UdpEndpoint.hpp:194
void close() noexcept
Close the socket. Idempotent.
Definition UdpEndpoint.cpp:44
UdpEndpoint & operator=(UdpEndpoint &&)=delete
bool tryReceive(UdpReceivedMessage &out)
Try to receive one datagram (non-blocking).
Definition UdpEndpoint.cpp:168
UdpEndpoint(const UdpEndpoint &)=delete
UdpEndpoint & operator=(const UdpEndpoint &)=delete
bool open(const char *bindAddr, Uint16 port)
Bind a UDP socket to bindAddr:port (server) or to any free port (client, with bindAddr = nullptr and ...
Definition UdpEndpoint.cpp:13
bool sendFragmented(const UdpEndpointAddr &dest, PacketHeader hdr, const void *data, int dataLen, int redundancy=1)
Send a payload by splitting it into MTU-safe fragments.
Definition UdpEndpoint.cpp:98
~UdpEndpoint()
Definition UdpEndpoint.hpp:116
bool sendDatagramBytes(const UdpEndpointAddr &dest, const void *bytes, int len)
Send an already encoded datagram to dest.
Definition UdpEndpoint.cpp:80
bool isOpen() const noexcept
True after a successful open.
Definition UdpEndpoint.hpp:188
UdpEndpoint(UdpEndpoint &&)=delete
bool send(const UdpEndpointAddr &dest, PacketHeader hdr, const void *payload, int payloadLen)
Send a payload with our header prefixed, to dest.
Definition UdpEndpoint.cpp:52
Definition ChatProtocol.cpp:12
A UDP datagram address (server's view of a remote peer).
Definition UdpEndpoint.hpp:49
void release() noexcept
Drop the refcount (idempotent).
Definition UdpEndpoint.hpp:86
UdpEndpointAddr(const UdpEndpointAddr &other)
Definition UdpEndpoint.hpp:55
UdpEndpointAddr & operator=(const UdpEndpointAddr &other)
Definition UdpEndpoint.hpp:58
NET_Address * addr
Refcounted SDL_net address.
Definition UdpEndpoint.hpp:50
~UdpEndpointAddr()
Definition UdpEndpoint.hpp:83
UdpEndpointAddr(UdpEndpointAddr &&other) noexcept
Definition UdpEndpoint.hpp:67
UdpEndpointAddr(NET_Address *address, Uint16 p)
Definition UdpEndpoint.hpp:54
Uint16 port
Source/destination port.
Definition UdpEndpoint.hpp:51
UdpEndpointAddr & operator=(UdpEndpointAddr &&other) noexcept
Definition UdpEndpoint.hpp:72
UdpEndpointAddr()=default
One framed UDP message ready to dispatch to upper layers.
Definition UdpEndpoint.hpp:97
UdpEndpointAddr from
Source address. Owns the NET_Address ref.
Definition UdpEndpoint.hpp:98
PacketHeader header
Parsed header.
Definition UdpEndpoint.hpp:99
std::vector< uint8_t > payload
Bytes after the header.
Definition UdpEndpoint.hpp:100