group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
net::UdpEndpoint Class Reference

Wraps a NET_DatagramSocket with header-prefixed I/O. More...

#include <UdpEndpoint.hpp>

Public Member Functions

 UdpEndpoint ()=default
 UdpEndpoint (const UdpEndpoint &)=delete
UdpEndpointoperator= (const UdpEndpoint &)=delete
 UdpEndpoint (UdpEndpoint &&)=delete
UdpEndpointoperator= (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 sendFragmented (const UdpEndpointAddr &dest, PacketHeader hdr, const void *data, int dataLen)
 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.

Private Attributes

NET_DatagramSocket * socket_ = nullptr

Detailed Description

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.

Constructor & Destructor Documentation

◆ UdpEndpoint() [1/3]

net::UdpEndpoint::UdpEndpoint ( )
default
Here is the caller graph for this function:

◆ UdpEndpoint() [2/3]

net::UdpEndpoint::UdpEndpoint ( const UdpEndpoint & )
delete
Here is the call graph for this function:

◆ UdpEndpoint() [3/3]

net::UdpEndpoint::UdpEndpoint ( UdpEndpoint && )
delete
Here is the call graph for this function:

◆ ~UdpEndpoint()

net::UdpEndpoint::~UdpEndpoint ( )
inline
Here is the call graph for this function:

Member Function Documentation

◆ close()

void net::UdpEndpoint::close ( )
noexcept

Close the socket. Idempotent.

Here is the caller graph for this function:

◆ isOpen()

bool net::UdpEndpoint::isOpen ( ) const
inlinenodiscardnoexcept

True after a successful open.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]

UdpEndpoint & net::UdpEndpoint::operator= ( const UdpEndpoint & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

UdpEndpoint & net::UdpEndpoint::operator= ( UdpEndpoint && )
delete
Here is the call graph for this function:

◆ send()

bool net::UdpEndpoint::send ( const UdpEndpointAddr & dest,
PacketHeader hdr,
const void * payload,
int payloadLen )

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.
Here is the caller graph for this function:

◆ sendFragmented()

bool net::UdpEndpoint::sendFragmented ( const UdpEndpointAddr & dest,
PacketHeader hdr,
const void * data,
int dataLen )

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
destDestination address.
hdrCaller-supplied header. flags and fragmentInfo are overwritten per-fragment.
dataPayload bytes (split internally).
dataLenTotal payload length.
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).
Here is the call graph for this function:

◆ tryReceive()

bool net::UdpEndpoint::tryReceive ( UdpReceivedMessage & out)

Try to receive one datagram (non-blocking).

Parameters
outFilled in on success.
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).
Here is the call graph for this function:

Member Data Documentation

◆ socket_

NET_DatagramSocket* net::UdpEndpoint::socket_ = nullptr
private

The documentation for this class was generated from the following files: