24#ifndef GOBY_MIDDLEWARE_IO_UDP_POINT_TO_POINT_H
25#define GOBY_MIDDLEWARE_IO_UDP_POINT_TO_POINT_H
31#include <boost/asio/buffer.hpp>
32#include <boost/asio/ip/udp.hpp>
33#include <boost/system/error_code.hpp>
54class UDPPointToPointConfig;
72 bool use_indexed_groups =
false>
74 :
public UDPOneToManyThread<line_in_group, line_out_group, publish_layer, subscribe_layer,
75 goby::middleware::protobuf::UDPPointToPointConfig, ThreadType,
87 :
Base(config, index, false)
89 boost::asio::ip::udp::resolver resolver(this->
mutable_io());
90 auto endpoints = resolver.resolve(this->cfg().remote_address(),
91 std::to_string(this->cfg().remote_port()),
92 boost::asio::ip::resolver_base::numeric_service);
93 if (endpoints.begin() == endpoints.end())
95 this->cfg().remote_address() +
":" +
96 std::to_string(this->cfg().remote_port())));
97 remote_endpoint_ = endpoints.begin()->endpoint();
100 this->interthread().template publish<line_in_group>(ready);
107 void async_write(std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg)
override;
110 boost::asio::ip::udp::endpoint remote_endpoint_;
120 bool use_indexed_groups>
122 subscribe_layer, ThreadType, use_indexed_groups>::
123 async_write(std::shared_ptr<const goby::middleware::protobuf::IOData> io_msg)
125 this->mutable_socket().async_send_to(
126 boost::asio::buffer(io_msg->data()), remote_endpoint_,
127 [
this, io_msg](
const boost::system::error_code& ec, std::size_t bytes_transferred)
129 if (!ec && bytes_transferred > 0)
131 this->handle_write_success(bytes_transferred);
135 this->handle_write_error(ec);
simple exception class for goby applications
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
~UDPPointToPointThread() override
UDPPointToPointThread(const goby::middleware::protobuf::UDPPointToPointConfig &config, int index=-1)
Constructs the thread.
boost::asio::io_context & mutable_io()
middleware::SimpleThread< Config, detail::InterProcessTag > SimpleThread
Zeromq-backed SimpleThread. Derives from middleware::SimpleThread using InterProcessTag.
The global namespace for the Goby project.