Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
core_lib::asio::udp::UdpSender Class Referencefinal

A general purpose UDP sender. More...

#include <UdpSender.h>

Public Member Functions

 UdpSender ()=delete
 Default constructor - deleted.
 
 UdpSender (boost_iocontext_t &ioContext, const defs::connection_t &receiver, eUdpOption sendOption=eUdpOption::broadcast, size_t sendBufferSize=DEFAULT_UDP_BUF_SIZE)
 Initialisation constructor. More...
 
 UdpSender (const defs::connection_t &receiver, eUdpOption sendOption=eUdpOption::broadcast, size_t sendBufferSize=DEFAULT_UDP_BUF_SIZE)
 Initialisation constructor. More...
 
 UdpSender (const UdpSender &)=delete
 Copy constructor - deleted.
 
UdpSenderoperator= (const UdpSender &)=delete
 Copy assignment operator - deleted.
 
 UdpSender (UdpSender &&)=delete
 Move constructor - deleted.
 
UdpSenderoperator= (UdpSender &&)=delete
 Move assignment operator - deleted.
 
 ~UdpSender ()=default
 Default destructor.
 
defs::connection_t ReceiverConnection () const
 Retrieve receiver connection details. More...
 
bool SendMessage (const defs::char_buffer_t &message)
 Send a message buffer to the receiver. More...
 

Private Member Functions

void CreateUdpSocket (eUdpOption sendOption, size_t sendBufferSize)
 Create UDP socket. More...
 
bool SyncSendTo (const defs::char_buffer_t &message)
 Synchronised send to method. More...
 

Private Attributes

std::unique_ptr< IoContextThreadGroupm_ioThreadGroup {}
 I/O context thread group.
 
defs::connection_t m_receiver {}
 Receiver connection details.
 
boost_udp_t::endpoint m_receiverEndpoint {}
 Recevier end-point.
 
boost_udp_t::resolver m_receiverResolver
 End-point resolver.
 
boost_udp_t::socket m_socket
 UDP socket.
 

Detailed Description

A general purpose UDP sender.

This class forms the underpinnings of the UdpTypedSender class.

Constructor & Destructor Documentation

◆ UdpSender() [1/2]

core_lib::asio::udp::UdpSender::UdpSender ( boost_iocontext_t ioContext,
const defs::connection_t receiver,
eUdpOption  sendOption = eUdpOption::broadcast,
size_t  sendBufferSize = DEFAULT_UDP_BUF_SIZE 
)

Initialisation constructor.

Parameters
[in]ioContext- External boost IO context to manage ASIO.
[in]receiver- Connection object describing target receiver's address and port.
[in]sendOption- Socket send option to control the use of broadcasts/unicast.
[in]sendBufferSize- Socket send option to control send buffer size.

Typically use this constructor when managing a bool of threads using an instance of core_lib::asio::IoContextThreadGroup in your application to manage a pool of std::threads. This means you can use a single thread pool and all ASIO operations will be exectued using this thread pool managed by a single IO context. This is the recommended constructor.

◆ UdpSender() [2/2]

core_lib::asio::udp::UdpSender::UdpSender ( const defs::connection_t receiver,
eUdpOption  sendOption = eUdpOption::broadcast,
size_t  sendBufferSize = DEFAULT_UDP_BUF_SIZE 
)
explicit

Initialisation constructor.

Parameters
[in]receiver- Connection object describing target receiver's address and port.
[in]sendOption- Socket send option to control the use of broadcasts/unicast.
[in]sendBufferSize- Socket send option to control send buffer size.

This constructor does not require an external IO context to run instead it creates its own IO context object along with its own thread. For very simple cases this version will be fine but in more performance and resource critical situations the external IO context constructor is recommened.

Member Function Documentation

◆ CreateUdpSocket()

void core_lib::asio::udp::UdpSender::CreateUdpSocket ( eUdpOption  sendOption,
size_t  sendBufferSize 
)
private

Create UDP socket.

Parameters
[in]sendOption- UDP send option.
[in]sendBufferSize- Send buffer size.

◆ ReceiverConnection()

auto core_lib::asio::udp::UdpSender::ReceiverConnection ( ) const

Retrieve receiver connection details.

Returns
- Connection object describing target receiver's address and port.

◆ SendMessage()

bool core_lib::asio::udp::UdpSender::SendMessage ( const defs::char_buffer_t message)

Send a message buffer to the receiver.

Parameters
[in]message- The message buffer.
Returns
Returns the success state of the send as a boolean.

◆ SyncSendTo()

bool core_lib::asio::udp::UdpSender::SyncSendTo ( const defs::char_buffer_t message)
private

Synchronised send to method.

Parameters
[in]message- Message buffer to send.
Returns
True if successfully sent, false otherwise.

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