24 #define INVALID_ENDPOINT boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0) // 0.0.0.0:0 45 size_t bytes_received;
46 boost::system::error_code ec;
47 boost::asio::ip::udp::endpoint current_endpoint;
50 this->
socket->receive_from(boost::asio::buffer(buffer, buffer_size), current_endpoint,
NO_FLAGS, ec);
55 case boost::system::errc::success: {
62 case boost::asio::error::would_block: {
68 throw boost::system::system_error(ec);
72 return bytes_received;
76 size_t bytes_received;
77 boost::system::error_code ec;
78 boost::asio::ip::udp::endpoint current_endpoint;
82 this->
socket->receive_from(boost::asio::buffer(buffer, buffer_size), current_endpoint,
NO_FLAGS, ec);
83 }
while (this->
socket->available() > 0);
88 case boost::system::errc::success: {
95 case boost::asio::error::would_block: {
101 throw boost::system::system_error(ec);
105 return bytes_received;
113 const boost::asio::ip::address receiver_boost_addr = boost::asio::ip::address::from_string(receiver_address);
114 this->
receiver_endpoint = boost::asio::ip::udp::endpoint(receiver_boost_addr, receiver_port);
129 if (this->
socket->is_open()) {
144 std::string error_msg =
"Error in receiver. Any-source not enabled.";
145 throw std::runtime_error(error_msg);
virtual void close_socket()
Close the socket.
boost::asio::ip::udp::socket * socket
void validate_sender_endpoint(boost::asio::ip::udp::endpoint current_sender_endpoint)
Validate whether the current sender endpoint matches the first sender endpoint when using specific so...
virtual void open_socket()=0
Open the socket with the desired options.
void reset(void)
Reset the receiver.
boost::asio::ip::udp::endpoint receiver_endpoint
size_t receive_latest(char *buffer, const size_t buffer_size)
Receive the latest data using UDP.
size_t receive(char *buffer, const size_t buffer_size)
Receive data using UDP.
boost::asio::io_context io_context
void set_receiver_endpoint(const std::string receiver_address, const short receiver_port)
Set the receiver endpoint.
Receiver(const std::string receiver_address, const short receiver_port)
Construct a new Receiver object.
void force_specific_source(bool specific_source)
Set wheter to enable any source or source specific. True for specific source, false for any source,...
virtual ~Receiver()
Destroy the Receiver object.
boost::asio::ip::udp::endpoint sender_endpoint