Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <NetworkSingleton.h>
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... | |
cNetworkLookup & | GetLookupThread () |
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 cNetworkSingleton & | Get (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... | |
Definition at line 38 of file NetworkSingleton.h.
cNetworkSingleton::cNetworkSingleton | ( | ) |
Definition at line 18 of file NetworkSingleton.cpp.
|
noexcept |
Definition at line 27 of file NetworkSingleton.cpp.
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.
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.
|
static |
Returns the singleton instance of this class.
Definition at line 37 of file NetworkSingleton.cpp.
|
inline |
Returns the main LibEvent handle for event registering.
Definition at line 57 of file NetworkSingleton.h.
|
inline |
Returns the thread used to perform hostname and IP lookups.
Definition at line 60 of file NetworkSingleton.h.
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.
|
staticprotected |
Converts LibEvent-generated log events into log messages in MCS log.
Definition at line 144 of file NetworkSingleton.cpp.
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.
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.
|
staticprotected |
Implements the thread that runs LibEvent's event dispatcher loop.
Definition at line 164 of file NetworkSingleton.cpp.
|
staticprotected |
Callback called by LibEvent when the event loop is started.
Definition at line 177 of file NetworkSingleton.cpp.
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.
|
protected |
Container for all client connections, including ones with pending-connect.
Definition at line 85 of file NetworkSingleton.h.
|
protected |
Mutex protecting all containers against multithreaded access.
Definition at line 91 of file NetworkSingleton.h.
|
protected |
The main LibEvent container for driving the event loop.
Definition at line 82 of file NetworkSingleton.h.
|
protected |
The thread in which the main LibEvent loop runs.
Definition at line 97 of file NetworkSingleton.h.
|
protected |
Set to true if Terminate has been called.
Definition at line 94 of file NetworkSingleton.h.
|
protected |
The thread on which hostname and ip address lookup is performed.
Definition at line 103 of file NetworkSingleton.h.
|
protected |
Container for all servers that are currently active.
Definition at line 88 of file NetworkSingleton.h.
|
protected |
Event that is signalled once the startup is finished and the LibEvent loop is running.
Definition at line 100 of file NetworkSingleton.h.