RADLib
RADical C++ application framework
RADNet::RADUdpSocket Class Reference

Event-loop integrated UDP socket. More...

#include <RADNet.h>

+ Inheritance diagram for RADNet::RADUdpSocket:
+ Collaboration diagram for RADNet::RADUdpSocket:

Public Member Functions

 RADUdpSocket (RADCore::EventLoop &loop)
 Creates a UDP socket whose events are posted to loop. More...
 
 ~RADUdpSocket ()
 Closes the socket and unregisters it from the reactor. More...
 
bool bind (uint16_t port, const std::string &address="0.0.0.0")
 Binds to address:port. Use port 0 to request an ephemeral port. More...
 
bool sendTo (const std::string &address, uint16_t port, const std::vector< uint8_t > &payload)
 Sends payload to address:port. More...
 
void close ()
 Closes the UDP file descriptor if open. More...
 
bool isOpen () const
 Returns true when the socket currently owns an open descriptor. More...
 
uint16_t localPort () const
 Returns the bound local port, or 0 when unavailable. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void(RADNet::Datagram) > datagramReceived
 Raised on the owning RADCore event loop when a datagram arrives. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when bind, send, receive, or reactor setup fails. More...
 

Detailed Description

Event-loop integrated UDP socket.

Constructor & Destructor Documentation

◆ RADUdpSocket()

RADNet::RADUdpSocket::RADUdpSocket ( RADCore::EventLoop loop)
explicit

Creates a UDP socket whose events are posted to loop.

◆ ~RADUdpSocket()

RADNet::RADUdpSocket::~RADUdpSocket ( )

Closes the socket and unregisters it from the reactor.

Member Function Documentation

◆ bind()

bool RADNet::RADUdpSocket::bind ( uint16_t  port,
const std::string &  address = "0.0.0.0" 
)

Binds to address:port. Use port 0 to request an ephemeral port.

◆ close()

void RADNet::RADUdpSocket::close ( )

Closes the UDP file descriptor if open.

◆ isOpen()

bool RADNet::RADUdpSocket::isOpen ( ) const

Returns true when the socket currently owns an open descriptor.

◆ localPort()

uint16_t RADNet::RADUdpSocket::localPort ( ) const

Returns the bound local port, or 0 when unavailable.

◆ sendTo()

bool RADNet::RADUdpSocket::sendTo ( const std::string &  address,
uint16_t  port,
const std::vector< uint8_t > &  payload 
)

Sends payload to address:port.

Member Data Documentation

◆ datagramReceived

RADCore::Event<void (RADNet::Datagram) > RADNet::RADUdpSocket::datagramReceived

Raised on the owning RADCore event loop when a datagram arrives.

◆ errorOccurred

RADCore::Event<void (std::string) > RADNet::RADUdpSocket::errorOccurred

Raised when bind, send, receive, or reactor setup fails.


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