24#ifndef GOBY_MIDDLEWARE_IO_LINE_BASED_TCP_CLIENT_H
25#define GOBY_MIDDLEWARE_IO_LINE_BASED_TCP_CLIENT_H
31#include <boost/asio/read_until.hpp>
32#include <boost/asio/streambuf.hpp>
33#include <boost/system/error_code.hpp>
73 bool use_indexed_groups =
false>
76 Config, ThreadType, use_indexed_groups>
79 subscribe_layer, Config, ThreadType, use_indexed_groups>;
87 :
Base(config, index), eol_matcher_(this->cfg().end_of_line())
95 void async_read()
override;
99 boost::asio::streambuf buffer_;
109 template <
class>
class ThreadType,
bool use_indexed_groups>
111 subscribe_layer, Config, ThreadType,
112 use_indexed_groups>::async_read()
114 boost::asio::async_read_until(
115 this->mutable_socket(), buffer_, eol_matcher_,
116 [
this](
const boost::system::error_code& ec, std::size_t bytes_transferred) {
117 if (!ec && bytes_transferred > 0)
119 auto io_msg = std::make_shared<goby::middleware::protobuf::IOData>();
120 auto& bytes = *io_msg->mutable_data();
121 bytes = std::string(bytes_transferred, 0);
122 std::istream is(&buffer_);
123 is.read(&bytes[0], bytes_transferred);
124 this->insert_endpoints(io_msg);
125 this->handle_read_success(bytes_transferred, io_msg);
130 this->handle_read_error(ec);
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Implements Thread for a three layer middleware setup ([ intervehicle [ interprocess [ interthread ] ]...
Reads/Writes strings from/to a TCP connection using a line-based (typically ASCII) protocol with a de...
~TCPClientThreadLineBased()
TCPClientThreadLineBased(const goby::middleware::protobuf::TCPClientConfig &config, int index=-1)
Constructs the thread.
Provides a matching function object for the boost::asio::async_read_until based on a std::regex.
The global namespace for the Goby project.