group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
MessageStream Class Reference

Length-prefixed framing layer over a TCP stream socket. More...

#include <MessageStream.hpp>

Public Member Functions

 MessageStream (NET_StreamSocket *sock)
 
bool send (const void *data, Uint32 size)
 Send a framed message over the socket.
 
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.
 

Public Attributes

NET_StreamSocket * socket = nullptr
 Underlying SDL_net stream socket.
 

Detailed Description

Length-prefixed framing layer over a TCP stream socket.

Wraps a raw NET_StreamSocket and handles splitting the byte stream into discrete messages. Each message is sent/received with a 4-byte big-endian length header followed by the payload bytes.

Constructor & Destructor Documentation

◆ MessageStream()

MessageStream::MessageStream ( NET_StreamSocket *  sock)
inline

Member Function Documentation

◆ poll()

bool MessageStream::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.

Parameters
callbackCalled with a pointer and length for each complete message.
Returns
False if the socket reports an error.
Here is the caller graph for this function:

◆ send()

bool MessageStream::send ( const void *  data,
Uint32  size 
)

Send a framed message over the socket.

Parameters
dataPointer to the payload bytes.
sizePayload length in bytes.
Returns
False if the send fails.
Here is the caller graph for this function:

Member Data Documentation

◆ socket

NET_StreamSocket* MessageStream::socket = nullptr

Underlying SDL_net stream socket.


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