14 m_Callbacks(
std::move(a_Callbacks))
26 if (endpoint !=
nullptr)
43 m_Self = std::move(a_Self);
56 if (endpoint ==
nullptr)
62 return endpoint->Send(a_Data, a_RemotePeer, a_RemotePort);
73 if (endpoint ==
nullptr)
79 return endpoint->GetPort();
90 if (endpoint ==
nullptr)
97 return endpoint->IsOpen();
108 if (endpoint !=
nullptr)
125 if (endpoint !=
nullptr)
127 endpoint->EnableBroadcasts();
156 if (endpoint !=
nullptr)
170 m_Callbacks->CallTableFn(
"OnReceivedData",
this,
AString(a_Data, a_NumBytes), a_RemotePeer, a_RemotePort);
180 m_Callbacks->CallTableFn(
"OnError", a_ErrorCode, a_ErrorMsg);
std::shared_ptr< cLuaUDPEndpoint > cLuaUDPEndpointPtr
std::unique_ptr< cTableRef > cTableRefPtr
cLuaState::cTableRefPtr m_Callbacks
The Lua table that holds the callbacks to be invoked.
virtual void OnReceivedData(const char *a_Data, size_t a_Size, const AString &a_RemotePeer, UInt16 a_RemotePort) override
Called when there is an incoming datagram from a remote host.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error occurs on the endpoint.
cLuaUDPEndpointPtr m_Self
SharedPtr to self, so that the object can keep itself alive for as long as it needs (for Lua).
virtual ~cLuaUDPEndpoint() override
void Terminated(void)
Common code called when the endpoint is considered as terminated.
void Close(void)
Closes the UDP listener.
cUDPEndpointPtr m_Endpoint
The underlying network endpoint.
void EnableBroadcasts(void)
Enables outgoing broadcasts to be made using this endpoint.
bool IsOpen(void) const
Returns true if the endpoint is open for incoming data.
UInt16 GetPort(void) const
Returns the port on which endpoint is listening for incoming data.
void Release(void)
Called when Lua garbage-collects the object.
cLuaUDPEndpoint(cLuaState::cTableRefPtr &&a_Callbacks)
Creates a new instance of the endpoint, wrapping the callbacks that are in the specified table.
bool Open(UInt16 a_Port, cLuaUDPEndpointPtr a_Self)
Opens the endpoint so that it starts listening for incoming data on the specified port.
bool Send(const AString &a_Data, const AString &a_RemotePeer, UInt16 a_RemotePort)
Sends the data contained in the string to the specified remote peer.
static cUDPEndpointPtr CreateUDPEndpoint(UInt16 a_Port, cUDPEndpoint::cCallbacks &a_Callbacks)
Opens up an UDP endpoint for sending and receiving UDP datagrams on the specified port.