My Project
Server Class Reference

#include <server.hpp>

Collaboration diagram for Server:

Public Types

typedef std::function< void(uint16_t, char *)> receiveCallbackType
 
typedef std::function< void(uint16_t)> newConnectionCallbackType
 
typedef std::function< void(uint16_t)> disconnectCallbackType
 

Public Member Functions

void init ()
 
void run ()
 
void stop ()
 
void onConnect (newConnectionCallbackType cb)
 
void onInput (receiveCallbackType cb)
 
void onDisconnect (disconnectCallbackType cb)
 
uint16_t sendMessage (int source_fd, const char *messageBuffer)
 
uint16_t sendMessage (int source_fd, char *messageBuffer)
 
void sendLoginAck (uint16_t fd, bool success, const char *errorMsg="")
 
void sendGuessAck (uint16_t fd, const GameState::guessResultT &res)
 

Static Public Member Functions

static void createInstance ()
 
static void createInstance (const int &)
 
static void destroyInstance ()
 
static ServergetInstance ()
 

Private Member Functions

 Server ()
 
 Server (const int &)
 
 Server (const Server &)=delete
 
virtual ~Server ()
 
void setup (int port)
 
void initializeSocket ()
 
void bindSocket ()
 
void startListen ()
 
void handleNewConnection ()
 
void recvInputFromExisting (int fd)
 

Private Attributes

fd_set masterfds
 
fd_set tmpfds
 
uint16_t maxfd
 
int mastersocket_fd
 
int tempsocket_fd
 
struct sockaddr_storage client_addr
 
struct sockaddr_in server_addr
 
char input_buffer [INPUT_BUFFER_SIZE]
 
char remote_ip [INET6_ADDRSTRLEN]
 
newConnectionCallbackType newConnectionCallback
 
receiveCallbackType receiveCallback
 
disconnectCallbackType disconnectCallback
 

Static Private Attributes

static Serverinstance
 

Member Typedef Documentation

◆ disconnectCallbackType

typedef std::function<void(uint16_t)> Server::disconnectCallbackType

◆ newConnectionCallbackType

typedef std::function<void(uint16_t)> Server::newConnectionCallbackType

◆ receiveCallbackType

typedef std::function<void(uint16_t, char *)> Server::receiveCallbackType

Constructor & Destructor Documentation

◆ Server() [1/3]

Server::Server ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Server() [2/3]

Server::Server ( const int &  port)
private
Here is the call graph for this function:

◆ Server() [3/3]

Server::Server ( const Server )
privatedelete

◆ ~Server()

Server::~Server ( )
privatevirtual

Member Function Documentation

◆ bindSocket()

void Server::bindSocket ( )
private
Here is the caller graph for this function:

◆ createInstance() [1/2]

void Server::createInstance ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createInstance() [2/2]

void Server::createInstance ( const int &  port)
static
Here is the call graph for this function:

◆ destroyInstance()

static void Server::destroyInstance ( )
inlinestatic

◆ getInstance()

static Server * Server::getInstance ( )
inlinestatic
Here is the caller graph for this function:

◆ handleNewConnection()

void Server::handleNewConnection ( )
private
Here is the caller graph for this function:

◆ init()

void Server::init ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initializeSocket()

void Server::initializeSocket ( )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ onConnect()

void Server::onConnect ( newConnectionCallbackType  cb)
Here is the caller graph for this function:

◆ onDisconnect()

void Server::onDisconnect ( disconnectCallbackType  cb)
Here is the caller graph for this function:

◆ onInput()

void Server::onInput ( receiveCallbackType  cb)
Here is the caller graph for this function:

◆ recvInputFromExisting()

void Server::recvInputFromExisting ( int  fd)
private
Here is the caller graph for this function:

◆ run()

void Server::run ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendGuessAck()

void Server::sendGuessAck ( uint16_t  fd,
const GameState::guessResultT res 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendLoginAck()

void Server::sendLoginAck ( uint16_t  fd,
bool  success,
const char *  errorMsg = "" 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessage() [1/2]

uint16_t Server::sendMessage ( int  source_fd,
char *  messageBuffer 
)

◆ sendMessage() [2/2]

uint16_t Server::sendMessage ( int  source_fd,
const char *  messageBuffer 
)
Here is the caller graph for this function:

◆ setup()

void Server::setup ( int  port)
private
Here is the caller graph for this function:

◆ startListen()

void Server::startListen ( )
private
Here is the caller graph for this function:

◆ stop()

void Server::stop ( )
Here is the caller graph for this function:

Member Data Documentation

◆ client_addr

struct sockaddr_storage Server::client_addr
private

◆ disconnectCallback

disconnectCallbackType Server::disconnectCallback
private

◆ input_buffer

char Server::input_buffer[INPUT_BUFFER_SIZE]
private

◆ instance

Server * Server::instance
staticprivate

◆ masterfds

fd_set Server::masterfds
private

◆ mastersocket_fd

int Server::mastersocket_fd
private

◆ maxfd

uint16_t Server::maxfd
private

◆ newConnectionCallback

newConnectionCallbackType Server::newConnectionCallback
private

◆ receiveCallback

receiveCallbackType Server::receiveCallback
private

◆ remote_ip

char Server::remote_ip[INET6_ADDRSTRLEN]
private

◆ server_addr

struct sockaddr_in Server::server_addr
private

◆ tempsocket_fd

int Server::tempsocket_fd
private

◆ tmpfds

fd_set Server::tmpfds
private

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