Cuberite
A lightweight, fast and extensible game server for Minecraft
UDPEndpointImpl.h
Go to the documentation of this file.
1 
2 // UDPEndpointImpl.h
3 
4 // Declares the cUDPEndpointImpl class representing an implementation of an endpoint in UDP communication
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "Network.h"
13 #include <event2/event.h>
14 
15 
16 
17 
18 
19 // fwd:
20 class cUDPEndpointImpl;
21 typedef std::shared_ptr<cUDPEndpointImpl> cUDPEndpointImplPtr;
22 
23 
24 
25 
26 
28  public cUDPEndpoint
29 {
31 
32 public:
33 
37  cUDPEndpointImpl(UInt16 a_Port, cUDPEndpoint::cCallbacks & a_Callbacks);
38 
39  virtual ~cUDPEndpointImpl() override;
40 
41  // cUDPEndpoint overrides:
42  virtual void Close(void) override;
43  virtual bool IsOpen(void) const override;
44  virtual UInt16 GetPort(void) const override;
45  virtual bool Send(const AString & a_Payload, const AString & a_Host, UInt16 a_Port) override;
46  virtual void EnableBroadcasts(void) override;
47 
48 protected:
52 
54  evutil_socket_t m_MainSock;
55 
58 
60  evutil_socket_t m_SecondarySock;
61 
63  event * m_MainEvent;
64 
67 
68 
72  void Open(UInt16 a_Port);
73 
76  static void RawCallback(evutil_socket_t a_Socket, short a_What, void * a_Self);
77 
79  void Callback(evutil_socket_t a_Socket, short a_What);
80 };
81 
82 
83 
84 
unsigned short UInt16
Definition: Globals.h:158
std::shared_ptr< cUDPEndpointImpl > cUDPEndpointImplPtr
std::string AString
Definition: StringUtils.h:11
Interface that provides methods available on UDP communication endpoints.
Definition: Network.h:176
cUDPEndpoint(cCallbacks &a_Callbacks)
Creates a new instance of an endpoint, with the specified callbacks.
Definition: Network.h:220
Interface for the callbacks for events that can happen on the endpoint.
Definition: Network.h:180
evutil_socket_t m_MainSock
The primary underlying OS socket.
virtual UInt16 GetPort(void) const override
Returns the local port to which the underlying socket is bound.
evutil_socket_t m_SecondarySock
The secondary OS socket (if primary doesn't support dualstack).
virtual void Close(void) override
Closes the underlying socket.
void Callback(evutil_socket_t a_Socket, short a_What)
The callback that is called when an event occurs on one of the sockets.
virtual ~cUDPEndpointImpl() override
virtual bool Send(const AString &a_Payload, const AString &a_Host, UInt16 a_Port) override
Sends the specified payload in a single UDP datagram to the specified host + port combination.
virtual bool IsOpen(void) const override
Returns true if the endpoint is open.
event * m_SecondaryEvent
The LibEvent handle for the secondary socket.
virtual void EnableBroadcasts(void) override
Marks the socket as capable of sending broadcast, using whatever OS API is needed.
UInt16 m_Port
The local port on which the endpoint is open.
static void RawCallback(evutil_socket_t a_Socket, short a_What, void *a_Self)
The callback that LibEvent calls when an event occurs on one of the sockets.
bool m_IsMainSockIPv6
True if m_MainSock is in the IPv6 namespace (needs IPv6 addresses for sending).
void Open(UInt16 a_Port)
Creates and opens the socket on the specified port.
event * m_MainEvent
The LibEvent handle for the primary socket.
cUDPEndpointImpl(UInt16 a_Port, cUDPEndpoint::cCallbacks &a_Callbacks)
Creates a new instance of the endpoint, with the specified callbacks.