Convenience object which receives data from a UDP socket and dispatches to a user defined callback. This object internally manages a single receive thread which is used to read data off the socket, and dispatch to the user callback. Note that the dispatch is serial with the UDP receive commands, so blocking callbacks will cause data to be dropped.
More...
#include <udp.hh>
|
| UdpReceiver (const NetworkSocket &socket, size_t max_mtu, std::function< void(const std::vector< uint8_t > &)> receive_callback) |
| Construct a UDP receiver for a given socket, and call a user callback whenever there is data available. The max_mtu will be the size of the internal buffer used to read data from the socket. More...
|
|
| ~UdpReceiver () |
|
|
std::vector< uint8_t > | m_incoming_buffer |
| Internal buffer used to write incoming UDP data into. More...
|
|
size_t | m_max_mtu = 0 |
| The amount of data to read off the socket during each read operation. More...
|
|
std::function< void(const std::vector< uint8_t > &)> | m_receive_callback |
| User specified callback which is called once UDP data is received. More...
|
|
std::thread | m_rx_thread |
| The rx_thread object which is spawned on construction. More...
|
|
socket_t | m_socket |
| The internal socket which UDP data is receive on. More...
|
|
std::atomic_bool | m_stop {false} |
| Atomic flag to stop the rx_thread on destruction. More...
|
|
Convenience object which receives data from a UDP socket and dispatches to a user defined callback. This object internally manages a single receive thread which is used to read data off the socket, and dispatch to the user callback. Note that the dispatch is serial with the UDP receive commands, so blocking callbacks will cause data to be dropped.
Definition at line 64 of file udp.hh.
◆ UdpReceiver()
multisense::legacy::UdpReceiver::UdpReceiver |
( |
const NetworkSocket & |
socket, |
|
|
size_t |
max_mtu, |
|
|
std::function< void(const std::vector< uint8_t > &)> |
receive_callback |
|
) |
| |
Construct a UDP receiver for a given socket, and call a user callback whenever there is data available. The max_mtu will be the size of the internal buffer used to read data from the socket.
Definition at line 47 of file udp.cc.
◆ ~UdpReceiver()
multisense::legacy::UdpReceiver::~UdpReceiver |
( |
| ) |
|
◆ rx_thread()
void multisense::legacy::UdpReceiver::rx_thread |
( |
| ) |
|
|
private |
The rx thread function which is receives UDP data.
Definition at line 71 of file udp.cc.
◆ m_incoming_buffer
std::vector<uint8_t> multisense::legacy::UdpReceiver::m_incoming_buffer |
|
private |
Internal buffer used to write incoming UDP data into.
Definition at line 109 of file udp.hh.
◆ m_max_mtu
size_t multisense::legacy::UdpReceiver::m_max_mtu = 0 |
|
private |
The amount of data to read off the socket during each read operation.
Definition at line 104 of file udp.hh.
◆ m_receive_callback
std::function<void(const std::vector<uint8_t>&)> multisense::legacy::UdpReceiver::m_receive_callback |
|
private |
User specified callback which is called once UDP data is received.
Definition at line 114 of file udp.hh.
◆ m_rx_thread
std::thread multisense::legacy::UdpReceiver::m_rx_thread |
|
private |
The rx_thread object which is spawned on construction.
Definition at line 94 of file udp.hh.
◆ m_socket
socket_t multisense::legacy::UdpReceiver::m_socket |
|
private |
The internal socket which UDP data is receive on.
Definition at line 89 of file udp.hh.
◆ m_stop
std::atomic_bool multisense::legacy::UdpReceiver::m_stop {false} |
|
private |
Atomic flag to stop the rx_thread on destruction.
Definition at line 99 of file udp.hh.
The documentation for this class was generated from the following files: