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

#include <LuaUDPEndpoint.h>

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

Public Member Functions

void Close (void)
 Closes the UDP listener. More...
 
 cLuaUDPEndpoint (cLuaState::cTableRefPtr &&a_Callbacks)
 Creates a new instance of the endpoint, wrapping the callbacks that are in the specified table. More...
 
void EnableBroadcasts (void)
 Enables outgoing broadcasts to be made using this endpoint. More...
 
UInt16 GetPort (void) const
 Returns the port on which endpoint is listening for incoming data. More...
 
bool IsOpen (void) const
 Returns true if the endpoint is open for incoming data. More...
 
bool Open (UInt16 a_Port, cLuaUDPEndpointPtr a_Self)
 Opens the endpoint so that it starts listening for incoming data on the specified port. More...
 
void Release (void)
 Called when Lua garbage-collects the object. More...
 
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. More...
 
virtual ~cLuaUDPEndpoint () override
 
- Public Member Functions inherited from cUDPEndpoint::cCallbacks
virtual ~cCallbacks ()
 

Protected Member Functions

virtual void OnError (int a_ErrorCode, const AString &a_ErrorMsg) override
 Called when an error occurs on the endpoint. More...
 
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. More...
 
void Terminated (void)
 Common code called when the endpoint is considered as terminated. More...
 

Protected Attributes

cLuaState::cTableRefPtr m_Callbacks
 The Lua table that holds the callbacks to be invoked. More...
 
cUDPEndpointPtr m_Endpoint
 The underlying network endpoint. More...
 
cLuaUDPEndpointPtr m_Self
 SharedPtr to self, so that the object can keep itself alive for as long as it needs (for Lua). More...
 

Detailed Description

Definition at line 27 of file LuaUDPEndpoint.h.

Constructor & Destructor Documentation

◆ cLuaUDPEndpoint()

cLuaUDPEndpoint::cLuaUDPEndpoint ( cLuaState::cTableRefPtr &&  a_Callbacks)

Creates a new instance of the endpoint, wrapping the callbacks that are in the specified table.

Definition at line 13 of file LuaUDPEndpoint.cpp.

◆ ~cLuaUDPEndpoint()

cLuaUDPEndpoint::~cLuaUDPEndpoint ( )
overridevirtual

Definition at line 22 of file LuaUDPEndpoint.cpp.

Member Function Documentation

◆ Close()

void cLuaUDPEndpoint::Close ( void  )

Closes the UDP listener.

Definition at line 104 of file LuaUDPEndpoint.cpp.

◆ EnableBroadcasts()

void cLuaUDPEndpoint::EnableBroadcasts ( void  )

Enables outgoing broadcasts to be made using this endpoint.

Definition at line 121 of file LuaUDPEndpoint.cpp.

◆ GetPort()

UInt16 cLuaUDPEndpoint::GetPort ( void  ) const

Returns the port on which endpoint is listening for incoming data.

Definition at line 69 of file LuaUDPEndpoint.cpp.

◆ IsOpen()

bool cLuaUDPEndpoint::IsOpen ( void  ) const

Returns true if the endpoint is open for incoming data.

Definition at line 86 of file LuaUDPEndpoint.cpp.

◆ OnError()

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

Called when an error occurs on the endpoint.

Implements cUDPEndpoint::cCallbacks.

Definition at line 177 of file LuaUDPEndpoint.cpp.

◆ OnReceivedData()

void cLuaUDPEndpoint::OnReceivedData ( const char *  a_Data,
size_t  a_Size,
const AString a_RemoteHost,
UInt16  a_RemotePort 
)
overrideprotectedvirtual

Called when there is an incoming datagram from a remote host.

Implements cUDPEndpoint::cCallbacks.

Definition at line 168 of file LuaUDPEndpoint.cpp.

◆ Open()

bool cLuaUDPEndpoint::Open ( UInt16  a_Port,
cLuaUDPEndpointPtr  a_Self 
)

Opens the endpoint so that it starts listening for incoming data on the specified port.

a_Self is the shared pointer to self that the object keeps to keep itself alive for as long as it needs (for Lua).

Definition at line 38 of file LuaUDPEndpoint.cpp.

◆ Release()

void cLuaUDPEndpoint::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 135 of file LuaUDPEndpoint.cpp.

◆ Send()

bool cLuaUDPEndpoint::Send ( const AString a_Data,
const AString a_RemotePeer,
UInt16  a_RemotePort 
)

Sends the data contained in the string to the specified remote peer.

Returns true if successful, false on immediate failure (queueing the data failed etc.)

Definition at line 52 of file LuaUDPEndpoint.cpp.

◆ Terminated()

void cLuaUDPEndpoint::Terminated ( void  )
protected

Common code called when the endpoint is considered as terminated.

Releases m_Endpoint and m_Callbacks, each when applicable.

Definition at line 148 of file LuaUDPEndpoint.cpp.

Member Data Documentation

◆ m_Callbacks

cLuaState::cTableRefPtr cLuaUDPEndpoint::m_Callbacks
protected

The Lua table that holds the callbacks to be invoked.

Definition at line 62 of file LuaUDPEndpoint.h.

◆ m_Endpoint

cUDPEndpointPtr cLuaUDPEndpoint::m_Endpoint
protected

The underlying network endpoint.

May be nullptr.

Definition at line 69 of file LuaUDPEndpoint.h.

◆ m_Self

cLuaUDPEndpointPtr cLuaUDPEndpoint::m_Self
protected

SharedPtr to self, so that the object can keep itself alive for as long as it needs (for Lua).

Definition at line 65 of file LuaUDPEndpoint.h.


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