VOX
A little voxel engine
|
The server side interface with the network module. More...
#include <Server.hpp>
Classes | |
class | ClientDisconnected |
struct | sendInfo |
arg struct used to send a packet More... | |
Public Types | |
enum | flags : uint8_t { ALL = 1 , ALLEXCEPT = 1 << 1 , ASYNC = 1 << 2 } |
Public Member Functions | |
Server (int port) | |
~Server () | |
Server (const Server &other)=delete | |
Server & | operator= (const Server &other)=delete |
Server (Server &&other)=delete | |
Server & | operator= (Server &&other)=delete |
void | runOnce (int timeout_ms) |
void | send (const sendInfo &info) |
void | ping (uint64_t id) |
send a ping packet to a client More... | |
void | disconnect (uint64_t id) |
disconnect a client More... | |
ThreadSafePacketQueue & | getIncomingPackets () |
Get a ref to the list of packet that have been received. More... | |
Public Attributes | |
std::unordered_map< uint64_t, std::chrono::time_point< std::chrono::high_resolution_clock > > | m_pings |
map used to store the time a ping was sent to a client More... | |
Static Public Attributes | |
static constexpr int | PING_TIMEOUT_MS = 5000 |
The server side interface with the network module.
This class is responsible for managing the connections and the packets to send and receive.
It is fully threadsafe and can be run in a separate thread. This is where packets are received and sent and where new connections are accepted.
About the sendInfo struct and the ASYNC flag: if the server is running on another thread this flag can be usefull. when this flag is set the send function will only queue the packet to be sent. All of the serialization and the syscalls will be done in the server thread. If the packet being sent isnt highly delay sensitive this flag should be used. It wont change anything regarding performances if the server is running on the same thread as the sending thread.
enum Server::flags : uint8_t |
Server::Server | ( | int | port | ) |
Server::~Server | ( | ) |
|
delete |
|
delete |
void Server::disconnect | ( | uint64_t | id | ) |
disconnect a client
id |
|
inline |
Get a ref to the list of packet that have been received.
void Server::ping | ( | uint64_t | id | ) |
send a ping packet to a client
id |
void Server::runOnce | ( | int | timeout_ms | ) |
void Server::send | ( | const sendInfo & | info | ) |
std::unordered_map<uint64_t, std::chrono::time_point<std::chrono::high_resolution_clock> > Server::m_pings |
map used to store the time a ping was sent to a client
|
staticconstexpr |