RAVENNAKIT
Loading...
Searching...
No Matches
rav::ExtendedUdpSocket Class Reference

A customized UDP socket class which extends usual UDP socket functionality by adding the ability to receive the destination address of a received packet. More...

#include <extended_udp_socket.hpp>

Classes

struct  RecvEvent

Public Types

using HandlerType = std::function<void(const RecvEvent& event)>

Public Member Functions

 ExtendedUdpSocket (boost::asio::io_context &io_context, const boost::asio::ip::udp::endpoint &endpoint)
 Construct a new instance of the class.
 ExtendedUdpSocket (boost::asio::io_context &io_context, const boost::asio::ip::address &interface_address, uint16_t port)
 Construct a new instance of the class.
 ExtendedUdpSocket (const ExtendedUdpSocket &)=delete
ExtendedUdpSocket & operator= (const ExtendedUdpSocket &)=delete
 ExtendedUdpSocket (ExtendedUdpSocket &&) noexcept=delete
ExtendedUdpSocket & operator= (ExtendedUdpSocket &&) noexcept=delete
 ~ExtendedUdpSocket ()
void start (HandlerType handler) const
 Start the receiver.
void send (const uint8_t *data, size_t size, const boost::asio::ip::udp::endpoint &endpoint) const
 Sends a datagram to the given endpoint.
boost::system::error_code join_multicast_group (const boost::asio::ip::address_v4 &multicast_address, const boost::asio::ip::address_v4 &interface_address) const
 Join a multicast group.
boost::system::error_code leave_multicast_group (const boost::asio::ip::address_v4 &multicast_address, const boost::asio::ip::address_v4 &interface_address) const
 Leave a multicast group.
boost::system::error_code set_multicast_outbound_interface (const boost::asio::ip::address_v4 &interface_address) const
 Set the outbound interface for multicast packets.
boost::system::error_code set_multicast_loopback (bool enable) const
 Set the multicast loopback option.
void set_dscp_value (int value) const
 Set the DSCP value for the socket.

Detailed Description

A customized UDP socket class which extends usual UDP socket functionality by adding the ability to receive the destination address of a received packet.

This is useful for RTP where sessions are defined by the source and destination endpoints. Also in cases where a single receiver is receiving from multiple senders, the destination address is needed to determine the source of the packet. This class also adds the ability to set dscp values for the socket.

Definition at line 46 of file extended_udp_socket.hpp.

Member Typedef Documentation

◆ HandlerType

using rav::ExtendedUdpSocket::HandlerType = std::function<void(const RecvEvent& event)>

Definition at line 56 of file extended_udp_socket.hpp.

Constructor & Destructor Documentation

◆ ExtendedUdpSocket() [1/4]

rav::ExtendedUdpSocket::ExtendedUdpSocket ( boost::asio::io_context & io_context,
const boost::asio::ip::udp::endpoint & endpoint )

Construct a new instance of the class.

Parameters
io_contextThe asio io_context to use.
endpointThe endpoint to bind to.

◆ ExtendedUdpSocket() [2/4]

rav::ExtendedUdpSocket::ExtendedUdpSocket ( boost::asio::io_context & io_context,
const boost::asio::ip::address & interface_address,
uint16_t port )

Construct a new instance of the class.

Parameters
io_contextThe asio io_context to use.
interface_addressThe address to bind to.
portThe port to bind to.

◆ ExtendedUdpSocket() [3/4]

rav::ExtendedUdpSocket::ExtendedUdpSocket ( const ExtendedUdpSocket & )
delete

◆ ExtendedUdpSocket() [4/4]

rav::ExtendedUdpSocket::ExtendedUdpSocket ( ExtendedUdpSocket && )
deletenoexcept

◆ ~ExtendedUdpSocket()

rav::ExtendedUdpSocket::~ExtendedUdpSocket ( )

Member Function Documentation

◆ join_multicast_group()

boost::system::error_code rav::ExtendedUdpSocket::join_multicast_group ( const boost::asio::ip::address_v4 & multicast_address,
const boost::asio::ip::address_v4 & interface_address ) const
nodiscard

Join a multicast group.

Parameters
multicast_addressThe multicast address to join.
interface_addressThe interface address to join the multicast group on.
Returns
Success if the operation was successful, error code otherwise.

◆ leave_multicast_group()

boost::system::error_code rav::ExtendedUdpSocket::leave_multicast_group ( const boost::asio::ip::address_v4 & multicast_address,
const boost::asio::ip::address_v4 & interface_address ) const
nodiscard

Leave a multicast group.

Parameters
multicast_addressThe multicast address to leave.
interface_addressThe interface address to leave the multicast group on.
Returns
Success if the operation was successful, error code otherwise.

◆ operator=() [1/2]

ExtendedUdpSocket & rav::ExtendedUdpSocket::operator= ( const ExtendedUdpSocket & )
delete

◆ operator=() [2/2]

ExtendedUdpSocket & rav::ExtendedUdpSocket::operator= ( ExtendedUdpSocket && )
deletenoexcept

◆ send()

void rav::ExtendedUdpSocket::send ( const uint8_t * data,
size_t size,
const boost::asio::ip::udp::endpoint & endpoint ) const

Sends a datagram to the given endpoint.

Parameters
dataThe data to send.
sizeThe size of the data. Must be smaller than MTU.
endpointThe endpoint to send the data to.

◆ set_dscp_value()

void rav::ExtendedUdpSocket::set_dscp_value ( int value) const

Set the DSCP value for the socket.

The value will be shifted 2 bits to the left, which sets the ECN bits to zero.

Parameters
valueThe DSCP value to set.

◆ set_multicast_loopback()

boost::system::error_code rav::ExtendedUdpSocket::set_multicast_loopback ( bool enable) const
nodiscard

Set the multicast loopback option.

Parameters
enableTrue to enable multicast loopback, false to disable.
Returns
True if the operation was successful, false otherwise.

◆ set_multicast_outbound_interface()

boost::system::error_code rav::ExtendedUdpSocket::set_multicast_outbound_interface ( const boost::asio::ip::address_v4 & interface_address) const
nodiscard

Set the outbound interface for multicast packets.

Parameters
interface_addressThe address of the interface to use.
Returns
True if the operation was successful, false otherwise.

◆ start()

void rav::ExtendedUdpSocket::start ( HandlerType handler) const

Start the receiver.

Parameters
handlerThe handler to receive incoming packets.

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