24 #ifndef GOBY_MIDDLEWARE_IO_LINE_BASED_TCP_SERVER_H
25 #define GOBY_MIDDLEWARE_IO_LINE_BASED_TCP_SERVER_H
32 #include <boost/asio/ip/tcp.hpp>
33 #include <boost/asio/read_until.hpp>
34 #include <boost/asio/streambuf.hpp>
35 #include <boost/system/error_code.hpp>
56 template <
typename TCPServerThreadType>
62 eol_matcher_(this->
cfg().end_of_line())
67 void async_read()
override
69 auto self(this->shared_from_this());
70 boost::asio::async_read_until(
72 [
this,
self](
const boost::system::error_code& ec, std::size_t bytes_transferred) {
73 if (!ec && bytes_transferred > 0)
75 auto io_msg = std::make_shared<goby::middleware::protobuf::IOData>();
76 auto& bytes = *io_msg->mutable_data();
77 bytes = std::string(bytes_transferred, 0);
78 std::istream is(&buffer_);
79 is.read(&bytes[0], bytes_transferred);
92 match_regex eol_matcher_;
93 boost::asio::streambuf buffer_;
104 bool use_indexed_groups =
false>
107 Config, ThreadType, use_indexed_groups>
110 subscribe_layer, Config, ThreadType, use_indexed_groups>;
116 void start_session(boost::asio::ip::tcp::socket tcp_socket)
118 std::make_shared<TCPSessionLineBased<Base>>(std::move(tcp_socket), *
this)->start();