group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
MessageStream.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <SDL3/SDL_stdinc.h>
7
8#include <SDL3_net/SDL_net.h>
9#include <cstring>
10#include <functional>
11#include <vector>
12
19{
20
21public:
22 MessageStream(NET_StreamSocket* sock) : socket(sock) {}
23
24 NET_StreamSocket* socket = nullptr;
25
30 bool send(const void* data, Uint32 size);
31
36 bool poll(const std::function<void(const void* data, Uint32 size)>& callback);
37
38private:
39 std::vector<Uint8> recvBuf;
40};
Length-prefixed framing layer over a TCP stream socket.
Definition MessageStream.hpp:19
MessageStream(NET_StreamSocket *sock)
Definition MessageStream.hpp:22
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:16
NET_StreamSocket * socket
Underlying SDL_net stream socket.
Definition MessageStream.hpp:24
bool send(const void *data, Uint32 size)
Send a framed message over the socket.
Definition MessageStream.cpp:6