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>
53 class TCPClientConfig;
73 bool use_indexed_groups =
false>
76 Config, ThreadType, use_indexed_groups>
79 subscribe_layer, Config, ThreadType, use_indexed_groups>;
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);