add send() function to client
This commit is contained in:
@@ -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_;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user