Wraps a NET_DatagramSocket with header-prefixed I/O.
More...
#include <UdpEndpoint.hpp>
|
| | UdpEndpoint ()=default |
| | UdpEndpoint (const UdpEndpoint &)=delete |
| UdpEndpoint & | operator= (const UdpEndpoint &)=delete |
| | UdpEndpoint (UdpEndpoint &&)=delete |
| UdpEndpoint & | operator= (UdpEndpoint &&)=delete |
| | ~UdpEndpoint () |
| 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 port = 0).
|
| void | close () noexcept |
| | Close the socket. Idempotent.
|
| bool | send (const UdpEndpointAddr &dest, PacketHeader hdr, const void *payload, int payloadLen) |
| | Send a payload with our header prefixed, to dest.
|
| bool | sendDatagramBytes (const UdpEndpointAddr &dest, const void *bytes, int len) |
| | Send an already encoded datagram to dest.
|
| 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.
|
| bool | tryReceive (UdpReceivedMessage &out) |
| | Try to receive one datagram (non-blocking).
|
| bool | isOpen () const noexcept |
| | True after a successful open.
|
| uint16_t | localPort () const noexcept |
| | Get the local port this socket is bound to.
|
|
| NET_DatagramSocket * | socket_ = nullptr |
Wraps a NET_DatagramSocket with header-prefixed I/O.
Same class is used in both server mode (binds to a port) and client mode (binds to any free port). Distinction is which open overload you call.
◆ UdpEndpoint() [1/3]
| net::UdpEndpoint::UdpEndpoint |
( |
| ) |
|
|
default |
◆ UdpEndpoint() [2/3]
| net::UdpEndpoint::UdpEndpoint |
( |
const UdpEndpoint & | | ) |
|
|
delete |
◆ UdpEndpoint() [3/3]
| net::UdpEndpoint::UdpEndpoint |
( |
UdpEndpoint && | | ) |
|
|
delete |
◆ ~UdpEndpoint()
| net::UdpEndpoint::~UdpEndpoint |
( |
| ) |
|
|
inline |
◆ close()
| void net::UdpEndpoint::close |
( |
| ) |
|
|
noexcept |
Close the socket. Idempotent.
◆ isOpen()
| bool net::UdpEndpoint::isOpen |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
True after a successful open.
◆ localPort()
| uint16_t net::UdpEndpoint::localPort |
( |
| ) |
const |
|
nodiscardnoexcept |
Get the local port this socket is bound to.
◆ open()
| bool net::UdpEndpoint::open |
( |
const char * | bindAddr, |
|
|
Uint16 | port ) |
Bind a UDP socket to bindAddr:port (server) or to any free port (client, with bindAddr = nullptr and port = 0).
- Returns
- False on bind / DNS / socket-creation failure.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ send()
Send a payload with our header prefixed, to dest.
Constructs the on-the-wire datagram = [PacketHeader][payload]. Caller fills the relevant header fields (channel / sequence / connectionId) — magic, version, kind=Payload, _pad are filled here.
- Returns
- False on socket error or oversize payload.
◆ sendDatagramBytes()
| bool net::UdpEndpoint::sendDatagramBytes |
( |
const UdpEndpointAddr & | dest, |
|
|
const void * | bytes, |
|
|
int | len ) |
Send an already encoded datagram to dest.
Used by relay wrappers and tests that need the complete [PacketHeader][payload] byte sequence as an opaque blob.
◆ sendFragmented()
| bool net::UdpEndpoint::sendFragmented |
( |
const UdpEndpointAddr & | dest, |
|
|
PacketHeader | hdr, |
|
|
const void * | data, |
|
|
int | dataLen, |
|
|
int | redundancy = 1 ) |
Send a payload by splitting it into MTU-safe fragments.
Stage 3d-4: snapshots at 100 players are ~5 KB, well over the MTU-safe k_maxPayloadBytes (~1184 bytes per single datagram). This helper splits data into ceil(len / k_maxPayloadBytes) fragments. Each fragment carries the same (channel, sequence) in its PacketHeader plus the bit-0-set flags.fragmented, with fragmentInfo packing (index << 8) | count.
The receiver pairs them by (connectionId, sequence) in a FragmentReassembler. Drop-stale: a newer sequence supersedes any in-progress reassembly. Single dropped fragment loses the whole snapshot — fine because the next snapshot lands ~31 ms later.
- Parameters
-
| dest | Destination address. |
| hdr | Caller-supplied header. flags and fragmentInfo are overwritten per-fragment. |
| data | Payload bytes (split internally). |
| dataLen | Total payload length. |
| redundancy | PR-15 (server-perf): send each individual fragment this many times back-to-back. Receivers' FragmentReassembler deduplicates by (sequence, fragmentIndex), so duplicate copies just fill any gaps left by single-copy losses. Default 1 = no redundancy (legacy behaviour). At redundancy = 2 and 5 % per- fragment loss, P(any single fragment lost) drops from 5 % → 5 ² = 0.25 %; for a 9-fragment FULL keyframe, P(at least one fragment fully lost) goes 37 % → 2 %. Used for FULL keyframes which can't tolerate any fragment loss (the entire snapshot is then unusable); DELTAs default to redundancy=1 since a single dropped delta only costs one frame's worth of state at PR-14's per-keyframe baseline. |
- Returns
- False on socket error or if the payload would need more than 256 fragments (sanity cap; 256 × ~1.18 KB ≈ 302 KB logical-message ceiling, vastly more than we'll need).
◆ tryReceive()
Try to receive one datagram (non-blocking).
- Parameters
-
- Returns
- True if a datagram was received and parsed; false if the queue was empty or the datagram was malformed (in which case it's silently dropped — UDP is best-effort).
◆ socket_
| NET_DatagramSocket* net::UdpEndpoint::socket_ = nullptr |
|
private |
The documentation for this class was generated from the following files: