9 #include "tolua++/include/tolua++.h"
16 m_Callbacks(
std::move(a_Callbacks)),
40 m_Self = std::move(a_Self);
51 if (ServerHandle ==
nullptr)
57 ServerHandle->Close();
65 for (
auto & conn: Connections)
83 if (ServerHandle ==
nullptr)
89 return ServerHandle->IsListening();
101 if (itr->get() == a_Link)
132 !LinkCallbacks->IsValid()
135 LOGINFO(
"cNetwork server (port %d) OnIncomingConnection callback failed. Dropping connection.",
m_Port);
140 auto res = std::make_shared<cLuaTCPLink>(std::move(LinkCallbacks),
m_Self);
166 m_Callbacks->CallTableFn(
"OnError", a_ErrorCode, a_ErrorMsg);
std::shared_ptr< cLuaServerHandle > cLuaServerHandlePtr
std::vector< cLuaTCPLinkPtr > cLuaTCPLinkPtrs
void LOGINFO(std::string_view a_Format, const Args &... args)
std::shared_ptr< cServerHandle > cServerHandlePtr
void SetServerHandle(cServerHandlePtr a_ServerHandle, cLuaServerHandlePtr a_Self)
Called by cNetwork::Listen()'s binding.
cLuaServerHandle(UInt16 a_Port, cLuaState::cTableRefPtr &&a_Callbacks)
Creates a new instance of the server handle, wrapping the (listen-) callbacks that are in the specifi...
bool IsListening(void)
Returns true if the server is currently listening.
void Close(void)
Terminates all connections and closes the listening socket.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when the socket fails to listen on the specified port.
void Release(void)
Called when Lua garbage-collects the object.
cServerHandlePtr m_ServerHandle
The cServerHandle around which this instance is wrapped.
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.
void RemoveLink(cLuaTCPLink *a_Link)
Removes the link from the list of links that the server is currently tracking.
cLuaServerHandlePtr m_Self
SharedPtr to self, given out to newly created links.
cLuaTCPLinkPtrs m_Connections
All connections that are currently active in this server.
cCriticalSection m_CSConnections
Protects m_Connections against multithreaded access.
cLuaState::cTableRefPtr m_Callbacks
The Lua table that holds the callbacks to be invoked.
UInt16 m_Port
The port on which the server is listening.
virtual void OnAccepted(cTCPLink &a_Link) override
Called when the TCP server created with Listen() creates a new link for an incoming connection.
virtual ~cLuaServerHandle() override
std::unique_ptr< cTableRef > cTableRefPtr
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
Interface that provides the methods available on a single TCP connection.
cCallbacksPtr GetCallbacks(void) const
Returns the callbacks that are used.
std::shared_ptr< cCallbacks > cCallbacksPtr