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::SimpleUdpReceiver Class Referencefinal

A simplified UDP receiver, which uses the class MessageHeader as the message header type. More...

#include <SimpleUdpReceiver.h>

Public Member Functions

 SimpleUdpReceiver ()=delete
 Default constructor - deleted.
 
 SimpleUdpReceiver (boost_iocontext_t &ioContext, uint16_t listenPort, const defs::default_message_dispatcher_t &messageDispatcher, eUdpOption receiveOptions=eUdpOption::broadcast, size_t receiveBufferSize=DEFAULT_UDP_BUF_SIZE, size_t memPoolMsgCount=0)
 Initialisation constructor. More...
 
 SimpleUdpReceiver (uint16_t listenPort, const defs::default_message_dispatcher_t &messageDispatcher, eUdpOption receiveOptions=eUdpOption::broadcast, size_t receiveBufferSize=DEFAULT_UDP_BUF_SIZE, size_t memPoolMsgCount=0)
 Initialisation constructor. More...
 
 SimpleUdpReceiver (const SimpleUdpReceiver &)=delete
 Copy constructor - deleted.
 
SimpleUdpReceiveroperator= (const SimpleUdpReceiver &)=delete
 Copy assignment operator - deleted.
 
 SimpleUdpReceiver (SimpleUdpReceiver &&)=delete
 Move constructor - deleted.
 
SimpleUdpReceiveroperator= (SimpleUdpReceiver &&)=delete
 Move assignment operator - deleted.
 
 ~SimpleUdpReceiver ()=default
 Default destructor.
 
uint16_t ListenPort () const
 Retrieve this receiver's listen port. More...
 

Private Attributes

messages::MessageHandler m_messageHandler {}
 Default message handler object of type core_lib::asio::messages::MessageHandler.
 
UdpReceiver m_udpReceiver
 Our actual typed UDP receiver object.
 

Detailed Description

A simplified UDP receiver, which uses the class MessageHeader as the message header type.

Constructor & Destructor Documentation

◆ SimpleUdpReceiver() [1/2]

core_lib::asio::udp::SimpleUdpReceiver::SimpleUdpReceiver ( boost_iocontext_t ioContext,
uint16_t  listenPort,
const defs::default_message_dispatcher_t messageDispatcher,
eUdpOption  receiveOptions = eUdpOption::broadcast,
size_t  receiveBufferSize = DEFAULT_UDP_BUF_SIZE,
size_t  memPoolMsgCount = 0 
)

Initialisation constructor.

Parameters
[in]ioContext- External boost IO context to manage ASIO.
[in]listenPort- Our listen port for all detected networks.
[in]messageDispatcher- Callback to use to dispatch received messages.
[in]receiveOptions- Socket receive option to control the use of broadcasts/unicast.
[in]receiveBufferSize- Socket receive option to control receive buffer size.
[in]memPoolMsgCount- Number of messages in pool for received message handling, defaults to 0, which implies no pool used.

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 executed using this thread pool managed by a single IO context. This is the recommended constructor.

NOTE: When the message pool feature is used then all messages passed to the the registered dispatcher are managed by the internal pool. Care must be taken in the dispatcher to process the messages as quickly as possibly so the pool doesn't fill and start overwriting older messages. If the messages need to be kept then it is the dispatchers job to make a suitable copy of the received message.

◆ SimpleUdpReceiver() [2/2]

core_lib::asio::udp::SimpleUdpReceiver::SimpleUdpReceiver ( uint16_t  listenPort,
const defs::default_message_dispatcher_t messageDispatcher,
eUdpOption  receiveOptions = eUdpOption::broadcast,
size_t  receiveBufferSize = DEFAULT_UDP_BUF_SIZE,
size_t  memPoolMsgCount = 0 
)

Initialisation constructor.

Parameters
[in]listenPort- Our listen port for all detected networks.
[in]messageDispatcher- Callback to use to dispatch received messages.
[in]receiveOptions- Socket receive option to control the use of broadcasts/unicast.
[in]receiveBufferSize- Socket receive option to control receive buffer size.
[in]memPoolMsgCount- Number of messages in pool for received message handling, defaults to 0, which implies no pool used.

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

NOTE: When the message pool feature is used then all messages passed to the the registered dispatcher are managed by the internal pool. Care must be taken in the dispatcher to process the messages as quickly as possibly so the pool doesn't fill and start overwriting older messages. If the messages need to be kept then it is the dispatchers job to make a suitable copy of the received message.

Member Function Documentation

◆ ListenPort()

uint16_t core_lib::asio::udp::SimpleUdpReceiver::ListenPort ( ) const

Retrieve this receiver's listen port.

Returns
The listen port.

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