VOX
A little voxel engine
Loading...
Searching...
No Matches
Server Class Reference

The server side interface with the network module. More...

#include <Server.hpp>

Collaboration diagram for Server:
Collaboration graph

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
 
Serveroperator= (const Server &other)=delete
 
 Server (Server &&other)=delete
 
Serveroperator= (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...
 
ThreadSafePacketQueuegetIncomingPackets ()
 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
 

Detailed Description

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.

Member Enumeration Documentation

◆ flags

enum Server::flags : uint8_t
Enumerator
ALL 
ALLEXCEPT 
ASYNC 

Constructor & Destructor Documentation

◆ Server() [1/3]

Server::Server ( int  port)

◆ ~Server()

Server::~Server ( )

◆ Server() [2/3]

Server::Server ( const Server other)
delete

◆ Server() [3/3]

Server::Server ( Server &&  other)
delete

Member Function Documentation

◆ disconnect()

void Server::disconnect ( uint64_t  id)

disconnect a client

Parameters
id

◆ getIncomingPackets()

ThreadSafePacketQueue & Server::getIncomingPackets ( )
inline

Get a ref to the list of packet that have been received.

Returns
ThreadSafePacketQueue&

◆ operator=() [1/2]

Server & Server::operator= ( const Server other)
delete

◆ operator=() [2/2]

Server & Server::operator= ( Server &&  other)
delete

◆ ping()

void Server::ping ( uint64_t  id)

send a ping packet to a client

Parameters
id

◆ runOnce()

void Server::runOnce ( int  timeout_ms)

◆ send()

void Server::send ( const sendInfo info)

Member Data Documentation

◆ m_pings

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

◆ PING_TIMEOUT_MS

constexpr int Server::PING_TIMEOUT_MS = 5000
staticconstexpr

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