Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
cNetworkSingleton Class Reference

#include <NetworkSingleton.h>

Collaboration diagram for cNetworkSingleton:
Collaboration graph
[legend]

Public Member Functions

void AddLink (const cTCPLinkPtr &a_Link)
 Adds the specified link to m_Connections. More...
 
void AddServer (const cServerHandlePtr &a_Server)
 Adds the specified link to m_Servers. More...
 
 cNetworkSingleton ()
 
event_base * GetEventBase (void)
 Returns the main LibEvent handle for event registering. More...
 
cNetworkLookupGetLookupThread ()
 Returns the thread used to perform hostname and IP lookups. More...
 
void Initialise (void)
 Initialises all network-related threads. More...
 
void RemoveLink (const cTCPLink *a_Link)
 Removes the specified link from m_Connections. More...
 
void RemoveServer (const cServerHandle *a_Server)
 Removes the specified server from m_Servers. More...
 
void Terminate (void)
 Terminates all network-related threads. More...
 
 ~cNetworkSingleton () noexcept(false)
 

Static Public Member Functions

static cNetworkSingletonGet (void)
 Returns the singleton instance of this class. More...
 

Static Protected Member Functions

static void LogCallback (int a_Severity, const char *a_Msg)
 Converts LibEvent-generated log events into log messages in MCS log. More...
 
static void RunEventLoop (cNetworkSingleton *a_Self)
 Implements the thread that runs LibEvent's event dispatcher loop. More...
 
static void SignalizeStartup (evutil_socket_t a_Socket, short a_Events, void *a_Self)
 Callback called by LibEvent when the event loop is started. More...
 

Protected Attributes

cTCPLinkPtrs m_Connections
 Container for all client connections, including ones with pending-connect. More...
 
cCriticalSection m_CS
 Mutex protecting all containers against multithreaded access. More...
 
event_base * m_EventBase
 The main LibEvent container for driving the event loop. More...
 
std::thread m_EventLoopThread
 The thread in which the main LibEvent loop runs. More...
 
std::atomic< bool > m_HasTerminated
 Set to true if Terminate has been called. More...
 
cNetworkLookup m_LookupThread
 The thread on which hostname and ip address lookup is performed. More...
 
cServerHandlePtrs m_Servers
 Container for all servers that are currently active. More...
 
cEvent m_StartupEvent
 Event that is signalled once the startup is finished and the LibEvent loop is running. More...
 

Detailed Description

Definition at line 38 of file NetworkSingleton.h.

Constructor & Destructor Documentation

◆ cNetworkSingleton()

cNetworkSingleton::cNetworkSingleton ( )

Definition at line 18 of file NetworkSingleton.cpp.

◆ ~cNetworkSingleton()

cNetworkSingleton::~cNetworkSingleton ( )
noexcept

Definition at line 27 of file NetworkSingleton.cpp.

Member Function Documentation

◆ AddLink()

void cNetworkSingleton::AddLink ( const cTCPLinkPtr a_Link)

Adds the specified link to m_Connections.

Used by the underlying link implementation when a new link is created.

Definition at line 188 of file NetworkSingleton.cpp.

◆ AddServer()

void cNetworkSingleton::AddServer ( const cServerHandlePtr a_Server)

Adds the specified link to m_Servers.

Used by the underlying server handle implementation when a new listening server is created. Only servers that succeed in listening are added.

Definition at line 217 of file NetworkSingleton.cpp.

◆ Get()

cNetworkSingleton & cNetworkSingleton::Get ( void  )
static

Returns the singleton instance of this class.

Definition at line 37 of file NetworkSingleton.cpp.

◆ GetEventBase()

event_base* cNetworkSingleton::GetEventBase ( void  )
inline

Returns the main LibEvent handle for event registering.

Definition at line 57 of file NetworkSingleton.h.

◆ GetLookupThread()

cNetworkLookup& cNetworkSingleton::GetLookupThread ( )
inline

Returns the thread used to perform hostname and IP lookups.

Definition at line 60 of file NetworkSingleton.h.

◆ Initialise()

void cNetworkSingleton::Initialise ( void  )

Initialises all network-related threads.

To be called on first run or after app restart.

Definition at line 47 of file NetworkSingleton.cpp.

◆ LogCallback()

void cNetworkSingleton::LogCallback ( int  a_Severity,
const char *  a_Msg 
)
staticprotected

Converts LibEvent-generated log events into log messages in MCS log.

Definition at line 144 of file NetworkSingleton.cpp.

◆ RemoveLink()

void cNetworkSingleton::RemoveLink ( const cTCPLink a_Link)

Removes the specified link from m_Connections.

Used by the underlying link implementation when the link is closed / errored.

Definition at line 199 of file NetworkSingleton.cpp.

◆ RemoveServer()

void cNetworkSingleton::RemoveServer ( const cServerHandle a_Server)

Removes the specified server from m_Servers.

Used by the underlying server handle implementation when the server is closed.

Definition at line 228 of file NetworkSingleton.cpp.

◆ RunEventLoop()

void cNetworkSingleton::RunEventLoop ( cNetworkSingleton a_Self)
staticprotected

Implements the thread that runs LibEvent's event dispatcher loop.

Definition at line 164 of file NetworkSingleton.cpp.

◆ SignalizeStartup()

void cNetworkSingleton::SignalizeStartup ( evutil_socket_t  a_Socket,
short  a_Events,
void *  a_Self 
)
staticprotected

Callback called by LibEvent when the event loop is started.

Definition at line 177 of file NetworkSingleton.cpp.

◆ Terminate()

void cNetworkSingleton::Terminate ( void  )

Terminates all network-related threads.

To be used only on app shutdown or restart. MSVC runtime requires that the LibEvent networking be shut down before the main() function is exitted; this is the way to do it.

Definition at line 98 of file NetworkSingleton.cpp.

Member Data Documentation

◆ m_Connections

cTCPLinkPtrs cNetworkSingleton::m_Connections
protected

Container for all client connections, including ones with pending-connect.

Definition at line 85 of file NetworkSingleton.h.

◆ m_CS

cCriticalSection cNetworkSingleton::m_CS
protected

Mutex protecting all containers against multithreaded access.

Definition at line 91 of file NetworkSingleton.h.

◆ m_EventBase

event_base* cNetworkSingleton::m_EventBase
protected

The main LibEvent container for driving the event loop.

Definition at line 82 of file NetworkSingleton.h.

◆ m_EventLoopThread

std::thread cNetworkSingleton::m_EventLoopThread
protected

The thread in which the main LibEvent loop runs.

Definition at line 97 of file NetworkSingleton.h.

◆ m_HasTerminated

std::atomic<bool> cNetworkSingleton::m_HasTerminated
protected

Set to true if Terminate has been called.

Definition at line 94 of file NetworkSingleton.h.

◆ m_LookupThread

cNetworkLookup cNetworkSingleton::m_LookupThread
protected

The thread on which hostname and ip address lookup is performed.

Definition at line 103 of file NetworkSingleton.h.

◆ m_Servers

cServerHandlePtrs cNetworkSingleton::m_Servers
protected

Container for all servers that are currently active.

Definition at line 88 of file NetworkSingleton.h.

◆ m_StartupEvent

cEvent cNetworkSingleton::m_StartupEvent
protected

Event that is signalled once the startup is finished and the LibEvent loop is running.

Definition at line 100 of file NetworkSingleton.h.


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