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

#include <LuaServerHandle.h>

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

Public Member Functions

void Close (void)
 Terminates all connections and closes the listening socket. More...
 
 cLuaServerHandle (UInt16 a_Port, cLuaState::cTableRefPtr &&a_Callbacks)
 Creates a new instance of the server handle, wrapping the (listen-) callbacks that are in the specified table. More...
 
bool IsListening (void)
 Returns true if the server is currently listening. More...
 
void Release (void)
 Called when Lua garbage-collects the object. More...
 
void RemoveLink (cLuaTCPLink *a_Link)
 Removes the link from the list of links that the server is currently tracking. More...
 
void SetServerHandle (cServerHandlePtr a_ServerHandle, cLuaServerHandlePtr a_Self)
 Called by cNetwork::Listen()'s binding. More...
 
virtual ~cLuaServerHandle () override
 
- Public Member Functions inherited from cNetwork::cListenCallbacks
virtual ~cListenCallbacks ()
 

Protected Member Functions

virtual void OnAccepted (cTCPLink &a_Link) override
 Called when the TCP server created with Listen() creates a new link for an incoming connection. More...
 
virtual void OnError (int a_ErrorCode, const AString &a_ErrorMsg) override
 Called when the socket fails to listen on the specified port. More...
 
virtual cTCPLink::cCallbacksPtr OnIncomingConnection (const AString &a_RemoteIPAddress, UInt16 a_RemotePort) override
 Called when the TCP server created with Listen() receives a new incoming connection. More...
 

Protected Attributes

cLuaState::cTableRefPtr m_Callbacks
 The Lua table that holds the callbacks to be invoked. More...
 
cLuaTCPLinkPtrs m_Connections
 All connections that are currently active in this server. More...
 
cCriticalSection m_CSConnections
 Protects m_Connections against multithreaded access. More...
 
UInt16 m_Port
 The port on which the server is listening. More...
 
cLuaServerHandlePtr m_Self
 SharedPtr to self, given out to newly created links. More...
 
cServerHandlePtr m_ServerHandle
 The cServerHandle around which this instance is wrapped. More...
 

Detailed Description

Definition at line 29 of file LuaServerHandle.h.

Constructor & Destructor Documentation

◆ cLuaServerHandle()

cLuaServerHandle::cLuaServerHandle ( UInt16  a_Port,
cLuaState::cTableRefPtr &&  a_Callbacks 
)

Creates a new instance of the server handle, wrapping the (listen-) callbacks that are in the specified table.

Definition at line 15 of file LuaServerHandle.cpp.

◆ ~cLuaServerHandle()

cLuaServerHandle::~cLuaServerHandle ( )
overridevirtual

Definition at line 25 of file LuaServerHandle.cpp.

Member Function Documentation

◆ Close()

void cLuaServerHandle::Close ( void  )

Terminates all connections and closes the listening socket.

Definition at line 47 of file LuaServerHandle.cpp.

◆ IsListening()

bool cLuaServerHandle::IsListening ( void  )

Returns true if the server is currently listening.

Definition at line 79 of file LuaServerHandle.cpp.

◆ OnAccepted()

void cLuaServerHandle::OnAccepted ( cTCPLink a_Link)
overrideprotectedvirtual

Called when the TCP server created with Listen() creates a new link for an incoming connection.

Provides the newly created Link that can be used for communication. Called right after a successful OnIncomingConnection().

Implements cNetwork::cListenCallbacks.

Definition at line 153 of file LuaServerHandle.cpp.

◆ OnError()

void cLuaServerHandle::OnError ( int  a_ErrorCode,
const AString a_ErrorMsg 
)
overrideprotectedvirtual

Called when the socket fails to listen on the specified port.

Implements cNetwork::cListenCallbacks.

Definition at line 163 of file LuaServerHandle.cpp.

◆ OnIncomingConnection()

cTCPLink::cCallbacksPtr cLuaServerHandle::OnIncomingConnection ( const AString a_RemoteIPAddress,
UInt16  a_RemotePort 
)
overrideprotectedvirtual

Called when the TCP server created with Listen() receives a new incoming connection.

Returns the link callbacks that the server should use for the newly created link. If a nullptr is returned, the connection is dropped immediately; otherwise a new cTCPLink instance is created and OnAccepted() is called.

Implements cNetwork::cListenCallbacks.

Definition at line 126 of file LuaServerHandle.cpp.

◆ Release()

void cLuaServerHandle::Release ( void  )

Called when Lua garbage-collects the object.

Releases the internal SharedPtr to self, so that the instance may be deallocated.

Definition at line 113 of file LuaServerHandle.cpp.

◆ RemoveLink()

void cLuaServerHandle::RemoveLink ( cLuaTCPLink a_Link)

Removes the link from the list of links that the server is currently tracking.

Definition at line 96 of file LuaServerHandle.cpp.

◆ SetServerHandle()

void cLuaServerHandle::SetServerHandle ( cServerHandlePtr  a_ServerHandle,
cLuaServerHandlePtr  a_Self 
)

Called by cNetwork::Listen()'s binding.

Sets the server handle around which this instance is wrapped, and a self SharedPtr for link management.

Definition at line 35 of file LuaServerHandle.cpp.

Member Data Documentation

◆ m_Callbacks

cLuaState::cTableRefPtr cLuaServerHandle::m_Callbacks
protected

The Lua table that holds the callbacks to be invoked.

Definition at line 58 of file LuaServerHandle.h.

◆ m_Connections

cLuaTCPLinkPtrs cLuaServerHandle::m_Connections
protected

All connections that are currently active in this server.

Protected by m_CSConnections.

Definition at line 72 of file LuaServerHandle.h.

◆ m_CSConnections

cCriticalSection cLuaServerHandle::m_CSConnections
protected

Protects m_Connections against multithreaded access.

Definition at line 68 of file LuaServerHandle.h.

◆ m_Port

UInt16 cLuaServerHandle::m_Port
protected

The port on which the server is listening.

Used mainly for better error reporting.

Definition at line 62 of file LuaServerHandle.h.

◆ m_Self

cLuaServerHandlePtr cLuaServerHandle::m_Self
protected

SharedPtr to self, given out to newly created links.

Definition at line 75 of file LuaServerHandle.h.

◆ m_ServerHandle

cServerHandlePtr cLuaServerHandle::m_ServerHandle
protected

The cServerHandle around which this instance is wrapped.

Definition at line 65 of file LuaServerHandle.h.


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