add send() function to client

This commit is contained in:
2022-04-26 19:31:09 +02:00
parent 7c76691df7
commit 06b00843d2
4 changed files with 25 additions and 50 deletions

View File

@@ -7,6 +7,7 @@
#include <vector>
#include "boost/bind.hpp"
#include "protocol.hpp"
namespace commons {
@@ -16,15 +17,14 @@ class client {
const boost::asio::ip::address& multicast_address,
short multicast_port, unsigned short tcp_port);
void init();
void set_outbound_interface(const boost::asio::ip::address_v4& address);
void handle_send_to(const boost::system::error_code& error);
void handle_timeout(const boost::system::error_code& error);
template <typename BufferType, typename HandlerFunc>
void send(const BufferType& buffer, HandlerFunc handler) {
socket_.async_send_to(buffer, endpoint_, handler);
}
private:
boost::asio::ip::udp::endpoint endpoint_;
boost::asio::ip::udp::socket socket_;
boost::asio::deadline_timer timer_;
std::string message_;
unsigned short port_;
};

View File

@@ -46,6 +46,14 @@ class generic_message_base
spdlog::debug("create_message is not implemented yet");
}
virtual void handle_sent(const boost::system::error_code& er) {
if (!er) {
spdlog::debug("Message was sent");
} else {
spdlog::error("Error occured on client::send");
}
}
protected:
bool is_handler = true;
};