Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost::asio multiple write multiple buffers into socket #104

Merged
merged 7 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion rtb/messaging/communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <rtb/common/concepts.hpp>

namespace vanilla { namespace messaging {

Expand Down Expand Up @@ -192,7 +193,12 @@ class sender : ConnectionPolicy
[](const boost::system::error_code&, std::size_t) {
});
}


template <std::invocable<boost::asio::ip::udp::socket &, boost::asio::ip::udp::endpoint const&> Callback>
void send_async(Callback && callback) {
std::forward<Callback>(callback)(socket_, to_endpoint_);
}

template<typename Handler>
void receive_async(Handler handler) {
socket_.async_receive_from(
Expand Down Expand Up @@ -273,6 +279,14 @@ class communicator {
}
return *this;
}

template <std::invocable<boost::asio::ip::udp::socket &, boost::asio::ip::udp::endpoint const&> Callback>
self_type & distribute(Callback && callback) {
if(distributor_) {
distributor_->send_async(std::forward<Callback>(callback));
}
return *this;
}

template<typename T, typename Handler>
self_type & process(Handler handler) {
Expand Down