Cuberite
A lightweight, fast and extensible game server for Minecraft
LuaUDPEndpoint.h
Go to the documentation of this file.
1 
2 // LuaUDPEndpoint.h
3 
4 // Declares the cLuaUDPEndpoint class representing a Lua wrapper for the cUDPEndpoint class and the callbacks it needs
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "../OSSupport/Network.h"
13 #include "LuaState.h"
14 
15 
16 
17 
18 
19 // fwd:
21 typedef std::shared_ptr<cLuaUDPEndpoint> cLuaUDPEndpointPtr;
22 
23 
24 
25 
26 
29 {
30 public:
33 
34  virtual ~cLuaUDPEndpoint() override;
35 
38  bool Open(UInt16 a_Port, cLuaUDPEndpointPtr a_Self);
39 
42  bool Send(const AString & a_Data, const AString & a_RemotePeer, UInt16 a_RemotePort);
43 
45  UInt16 GetPort(void) const;
46 
48  bool IsOpen(void) const;
49 
51  void Close(void);
52 
54  void EnableBroadcasts(void);
55 
58  void Release(void);
59 
60 protected:
63 
66 
70 
71 
74  void Terminated(void);
75 
76  // cUDPEndpoint::cCallbacks overrides:
77  virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override;
78  virtual void OnReceivedData(const char * a_Data, size_t a_Size, const AString & a_RemotePeer, UInt16 a_RemotePort) override;
79 };
80 
81 
82 
83 
cLuaState::cTableRefPtr m_Callbacks
The Lua table that holds the callbacks to be invoked.
UInt16 GetPort(void) const
Returns the port on which endpoint is listening for incoming data.
std::unique_ptr< cTableRef > cTableRefPtr
Definition: LuaState.h:420
bool IsOpen(void) const
Returns true if the endpoint is open for incoming data.
cLuaUDPEndpoint(cLuaState::cTableRefPtr &&a_Callbacks)
Creates a new instance of the endpoint, wrapping the callbacks that are in the specified table...
std::shared_ptr< cUDPEndpoint > cUDPEndpointPtr
Definition: Network.h:217
Interface for the callbacks for events that can happen on the endpoint.
Definition: Network.h:170
cUDPEndpointPtr m_Endpoint
The underlying network endpoint.
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.
std::shared_ptr< cLuaUDPEndpoint > cLuaUDPEndpointPtr
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 Close(void)
Closes the UDP listener.
void Release(void)
Called when Lua garbage-collects the object.
void EnableBroadcasts(void)
Enables outgoing broadcasts to be made using this endpoint.
unsigned short UInt16
Definition: Globals.h:114
std::string AString
Definition: StringUtils.h:13
void Terminated(void)
Common code called when the endpoint is considered as terminated.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error occurs on the endpoint.
bool Open(UInt16 a_Port, cLuaUDPEndpointPtr a_Self)
Opens the endpoint so that it starts listening for incoming data on the specified port...
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.