6#include <SDL3/SDL_stdinc.h>
8#include <SDL3_net/SDL_net.h>
46 bool send(
const void* data, Uint32 size);
52 bool poll(
const std::function<
void(
const void* data, Uint32 size)>& callback);
70 void drainComplete(
const std::function<
void(
const void* data, Uint32 size)>& callback);
std::vector< Uint8 > recvBuf
Accumulates partial data between poll() calls.
Definition MessageStream.hpp:82
MessageStream()=default
PR-5b: default-construct so server Connection (which embeds a MessageStream) can be try_emplace'd int...
MessageStream(NET_StreamSocket *sock)
Definition MessageStream.hpp:38
void drainComplete(const std::function< void(const void *data, Uint32 size)> &callback)
Decode-only half of poll(): invoke the callback for each complete message currently buffered.
Definition MessageStream.cpp:72
bool pumpReads()
Read-only half of poll(): drain the kernel into recvBuf.
Definition MessageStream.cpp:44
Uint32 recvAvailable() const noexcept
Bytes available for parsing in recvBuf, starting at recvHead.
Definition MessageStream.hpp:74
void recvCompact()
Compact recvBuf: shift unconsumed bytes to the front, reset head.
Definition MessageStream.cpp:32
bool poll(const std::function< void(const void *data, Uint32 size)> &callback)
Read all available bytes from the socket and invoke the callback once per complete message frame.
Definition MessageStream.cpp:102
NET_StreamSocket * socket
Underlying SDL_net stream socket.
Definition MessageStream.hpp:40
const Uint8 * recvFront() const noexcept
Pointer to the first unconsumed byte.
Definition MessageStream.hpp:77
Uint32 recvHead
Offset of next unconsumed byte in recvBuf (avoids O(N) erase).
Definition MessageStream.hpp:83
bool send(const void *data, Uint32 size)
Send a framed message over the socket.
Definition MessageStream.cpp:22