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

#include <ServerHandleImpl.h>

Inheritance diagram for cServerHandleImpl:
Inheritance graph
[legend]
Collaboration diagram for cServerHandleImpl:
Collaboration graph
[legend]

Public Member Functions

virtual void Close (void) override
 Stops the server, no more incoming connections will be accepted. More...
 
virtual bool IsListening (void) const override
 Returns true if the server has been started correctly and is currently listening for incoming connections. More...
 
virtual ~cServerHandleImpl () override
 Closes the server, dropping all the connections. More...
 
- Public Member Functions inherited from cServerHandle
virtual ~cServerHandle ()
 

Static Public Member Functions

static cServerHandleImplPtr Listen (UInt16 a_Port, cNetwork::cListenCallbacksPtr a_ListenCallbacks)
 Creates a new server instance listening on the specified port. More...
 

Protected Member Functions

 cServerHandleImpl (cNetwork::cListenCallbacksPtr a_ListenCallbacks)
 Creates a new instance with the specified callbacks. More...
 
bool Listen (UInt16 a_Port)
 Starts listening on the specified port. More...
 
void RemoveLink (const cTCPLinkImpl *a_Link)
 Removes the specified link from m_Connections. More...
 

Static Protected Member Functions

static void Callback (evconnlistener *a_Listener, evutil_socket_t a_Socket, sockaddr *a_Addr, int a_Len, void *a_Self)
 The callback called by LibEvent upon incoming connection. More...
 

Protected Attributes

cTCPLinkImplPtrs m_Connections
 Container for all currently active connections on this server. More...
 
evconnlistener * m_ConnListener
 The LibEvent handle representing the main listening socket. More...
 
cCriticalSection m_CS
 Mutex protecting m_Connections againt multithreaded access. More...
 
int m_ErrorCode
 Contains the error code for the failure to listen. More...
 
AString m_ErrorMsg
 Contains the error message for the failure to listen. More...
 
bool m_IsListening
 Set to true when the server is initialized successfully and is listening for incoming connections. More...
 
cNetwork::cListenCallbacksPtr m_ListenCallbacks
 The callbacks used to notify about incoming connections. More...
 
evconnlistener * m_SecondaryConnListener
 The LibEvent handle representing the secondary listening socket (only when side-by-side listening is needed, such as WinXP). More...
 
cServerHandleImplPtr m_SelfPtr
 The SharedPtr to self, so that it can be passed to created links. More...
 

Private Types

using Super = cServerHandle
 

Friends

class cTCPLinkImpl
 

Detailed Description

Definition at line 34 of file ServerHandleImpl.h.

Member Typedef Documentation

◆ Super

Definition at line 37 of file ServerHandleImpl.h.

Constructor & Destructor Documentation

◆ ~cServerHandleImpl()

cServerHandleImpl::~cServerHandleImpl ( )
overridevirtual

Closes the server, dropping all the connections.

Definition at line 50 of file ServerHandleImpl.cpp.

◆ cServerHandleImpl()

cServerHandleImpl::cServerHandleImpl ( cNetwork::cListenCallbacksPtr  a_ListenCallbacks)
protected

Creates a new instance with the specified callbacks.

Initializes the internals, but doesn't start listening yet.

Definition at line 37 of file ServerHandleImpl.cpp.

Member Function Documentation

◆ Callback()

void cServerHandleImpl::Callback ( evconnlistener *  a_Listener,
evutil_socket_t  a_Socket,
sockaddr *  a_Addr,
int  a_Len,
void *  a_Self 
)
staticprotected

The callback called by LibEvent upon incoming connection.

Definition at line 294 of file ServerHandleImpl.cpp.

◆ Close()

void cServerHandleImpl::Close ( void  )
overridevirtual

Stops the server, no more incoming connections will be accepted.

All current connections will be shut down (cTCPLink::Shutdown()).

Implements cServerHandle.

Definition at line 66 of file ServerHandleImpl.cpp.

◆ IsListening()

virtual bool cServerHandleImpl::IsListening ( void  ) const
inlineoverridevirtual

Returns true if the server has been started correctly and is currently listening for incoming connections.

Implements cServerHandle.

Definition at line 55 of file ServerHandleImpl.h.

◆ Listen() [1/2]

bool cServerHandleImpl::Listen ( UInt16  a_Port)
protected

Starts listening on the specified port.

Returns true if successful, false on failure. On failure, sets m_ErrorCode and m_ErrorMsg.

Definition at line 124 of file ServerHandleImpl.cpp.

◆ Listen() [2/2]

cServerHandleImplPtr cServerHandleImpl::Listen ( UInt16  a_Port,
cNetwork::cListenCallbacksPtr  a_ListenCallbacks 
)
static

Creates a new server instance listening on the specified port.

Both IPv4 and IPv6 interfaces are used, if possible. Always returns a server instance; in the event of a failure, the instance holds the error details. Use IsListening() to query success.

Definition at line 101 of file ServerHandleImpl.cpp.

◆ RemoveLink()

void cServerHandleImpl::RemoveLink ( const cTCPLinkImpl a_Link)
protected

Removes the specified link from m_Connections.

Called by cTCPLinkImpl when the link is terminated.

Definition at line 351 of file ServerHandleImpl.cpp.

Friends And Related Function Documentation

◆ cTCPLinkImpl

friend class cTCPLinkImpl
friend

Definition at line 38 of file ServerHandleImpl.h.

Member Data Documentation

◆ m_Connections

cTCPLinkImplPtrs cServerHandleImpl::m_Connections
protected

Container for all currently active connections on this server.

Definition at line 71 of file ServerHandleImpl.h.

◆ m_ConnListener

evconnlistener* cServerHandleImpl::m_ConnListener
protected

The LibEvent handle representing the main listening socket.

Definition at line 62 of file ServerHandleImpl.h.

◆ m_CS

cCriticalSection cServerHandleImpl::m_CS
protected

Mutex protecting m_Connections againt multithreaded access.

Definition at line 74 of file ServerHandleImpl.h.

◆ m_ErrorCode

int cServerHandleImpl::m_ErrorCode
protected

Contains the error code for the failure to listen.

Only valid for non-listening instances.

Definition at line 77 of file ServerHandleImpl.h.

◆ m_ErrorMsg

AString cServerHandleImpl::m_ErrorMsg
protected

Contains the error message for the failure to listen.

Only valid for non-listening instances.

Definition at line 80 of file ServerHandleImpl.h.

◆ m_IsListening

bool cServerHandleImpl::m_IsListening
protected

Set to true when the server is initialized successfully and is listening for incoming connections.

Definition at line 68 of file ServerHandleImpl.h.

◆ m_ListenCallbacks

cNetwork::cListenCallbacksPtr cServerHandleImpl::m_ListenCallbacks
protected

The callbacks used to notify about incoming connections.

Definition at line 59 of file ServerHandleImpl.h.

◆ m_SecondaryConnListener

evconnlistener* cServerHandleImpl::m_SecondaryConnListener
protected

The LibEvent handle representing the secondary listening socket (only when side-by-side listening is needed, such as WinXP).

Definition at line 65 of file ServerHandleImpl.h.

◆ m_SelfPtr

cServerHandleImplPtr cServerHandleImpl::m_SelfPtr
protected

The SharedPtr to self, so that it can be passed to created links.

Definition at line 83 of file ServerHandleImpl.h.


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