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

#include <UDPEndpointImpl.h>

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

Public Member Functions

virtual void Close (void) override
 Closes the underlying socket. More...
 
 cUDPEndpointImpl (UInt16 a_Port, cUDPEndpoint::cCallbacks &a_Callbacks)
 Creates a new instance of the endpoint, with the specified callbacks. More...
 
virtual void EnableBroadcasts (void) override
 Marks the socket as capable of sending broadcast, using whatever OS API is needed. More...
 
virtual UInt16 GetPort (void) const override
 Returns the local port to which the underlying socket is bound. More...
 
virtual bool IsOpen (void) const override
 Returns true if the endpoint is open. More...
 
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. More...
 
virtual ~cUDPEndpointImpl () override
 
- Public Member Functions inherited from cUDPEndpoint
virtual ~cUDPEndpoint ()
 

Protected Member Functions

void Callback (evutil_socket_t a_Socket, short a_What)
 The callback that is called when an event occurs on one of the sockets. More...
 
void Open (UInt16 a_Port)
 Creates and opens the socket on the specified port. More...
 
- Protected Member Functions inherited from cUDPEndpoint
 cUDPEndpoint (cCallbacks &a_Callbacks)
 Creates a new instance of an endpoint, with the specified callbacks. More...
 

Static Protected Member Functions

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. More...
 

Protected Attributes

bool m_IsMainSockIPv6
 True if m_MainSock is in the IPv6 namespace (needs IPv6 addresses for sending). More...
 
event * m_MainEvent
 The LibEvent handle for the primary socket. More...
 
evutil_socket_t m_MainSock
 The primary underlying OS socket. More...
 
UInt16 m_Port
 The local port on which the endpoint is open. More...
 
event * m_SecondaryEvent
 The LibEvent handle for the secondary socket. More...
 
evutil_socket_t m_SecondarySock
 The secondary OS socket (if primary doesn't support dualstack). More...
 
- Protected Attributes inherited from cUDPEndpoint
cCallbacksm_Callbacks
 The callbacks used for various events on the endpoint. More...
 

Private Types

using Super = cUDPEndpoint
 

Detailed Description

Definition at line 27 of file UDPEndpointImpl.h.

Member Typedef Documentation

◆ Super

Definition at line 30 of file UDPEndpointImpl.h.

Constructor & Destructor Documentation

◆ cUDPEndpointImpl()

cUDPEndpointImpl::cUDPEndpointImpl ( UInt16  a_Port,
cUDPEndpoint::cCallbacks a_Callbacks 
)

Creates a new instance of the endpoint, with the specified callbacks.

Tries to open on the specified port; if it fails, the endpoint is left in the "closed" state. If a_Port is 0, the OS is free to assign any port number it likes to the endpoint.

Definition at line 187 of file UDPEndpointImpl.cpp.

◆ ~cUDPEndpointImpl()

cUDPEndpointImpl::~cUDPEndpointImpl ( )
overridevirtual

Definition at line 203 of file UDPEndpointImpl.cpp.

Member Function Documentation

◆ Callback()

void cUDPEndpointImpl::Callback ( evutil_socket_t  a_Socket,
short  a_What 
)
protected

The callback that is called when an event occurs on one of the sockets.

Definition at line 571 of file UDPEndpointImpl.cpp.

◆ Close()

void cUDPEndpointImpl::Close ( void  )
overridevirtual

Closes the underlying socket.

Note that there still might be callbacks in-flight after this method returns.

Implements cUDPEndpoint.

Definition at line 212 of file UDPEndpointImpl.cpp.

◆ EnableBroadcasts()

void cUDPEndpointImpl::EnableBroadcasts ( void  )
overridevirtual

Marks the socket as capable of sending broadcast, using whatever OS API is needed.

Without this call, sending to a broadcast address using Send() may fail.

Implements cUDPEndpoint.

Definition at line 326 of file UDPEndpointImpl.cpp.

◆ GetPort()

UInt16 cUDPEndpointImpl::GetPort ( void  ) const
overridevirtual

Returns the local port to which the underlying socket is bound.

Implements cUDPEndpoint.

Definition at line 255 of file UDPEndpointImpl.cpp.

◆ IsOpen()

bool cUDPEndpointImpl::IsOpen ( void  ) const
overridevirtual

Returns true if the endpoint is open.

Implements cUDPEndpoint.

Definition at line 246 of file UDPEndpointImpl.cpp.

◆ Open()

void cUDPEndpointImpl::Open ( UInt16  a_Port)
protected

Creates and opens the socket on the specified port.

If a_Port is 0, the OS is free to assign any port number it likes to the endpoint. If the opening fails, the OnError() callback is called and the endpoint is left "closed" (IsOpen() returns false).

Definition at line 371 of file UDPEndpointImpl.cpp.

◆ RawCallback()

void cUDPEndpointImpl::RawCallback ( evutil_socket_t  a_Socket,
short  a_What,
void *  a_Self 
)
staticprotected

The callback that LibEvent calls when an event occurs on one of the sockets.

Calls Callback() on a_Self.

Definition at line 561 of file UDPEndpointImpl.cpp.

◆ Send()

bool cUDPEndpointImpl::Send ( const AString a_Payload,
const AString a_Host,
UInt16  a_Port 
)
overridevirtual

Sends the specified payload in a single UDP datagram to the specified host + port combination.

Note that in order to send to a broadcast address, you need to call EnableBroadcasts() first.

Implements cUDPEndpoint.

Definition at line 264 of file UDPEndpointImpl.cpp.

Member Data Documentation

◆ m_IsMainSockIPv6

bool cUDPEndpointImpl::m_IsMainSockIPv6
protected

True if m_MainSock is in the IPv6 namespace (needs IPv6 addresses for sending).

Definition at line 57 of file UDPEndpointImpl.h.

◆ m_MainEvent

event* cUDPEndpointImpl::m_MainEvent
protected

The LibEvent handle for the primary socket.

Definition at line 63 of file UDPEndpointImpl.h.

◆ m_MainSock

evutil_socket_t cUDPEndpointImpl::m_MainSock
protected

The primary underlying OS socket.

Definition at line 54 of file UDPEndpointImpl.h.

◆ m_Port

UInt16 cUDPEndpointImpl::m_Port
protected

The local port on which the endpoint is open.

If this is zero, it means the endpoint is closed - either opening has failed, or it has been closed explicitly.

Definition at line 51 of file UDPEndpointImpl.h.

◆ m_SecondaryEvent

event* cUDPEndpointImpl::m_SecondaryEvent
protected

The LibEvent handle for the secondary socket.

Definition at line 66 of file UDPEndpointImpl.h.

◆ m_SecondarySock

evutil_socket_t cUDPEndpointImpl::m_SecondarySock
protected

The secondary OS socket (if primary doesn't support dualstack).

Definition at line 60 of file UDPEndpointImpl.h.


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