我读到可以使用boost::asio::read_until
从套接字中读取,所以我尝试这样做:
using namespace boost::asio;
...
boost::array<char, BUFFER_SIZE> buf;
read_until(this->socket_opt.value(), buffer(buf), "n");
但显然,read_until无法接受这些论点:
error: no matching function for call to ‘read_until(const boost::asio::basic_stream_socket<boost::asio::ip::tcp>&, boost::asio::mutable_buffers_1, const char [2])’
read_until(this->socket_opt.value(), buffer(buf), "n");
我做错了什么?
p.S.socket_opt被定义为std::optional<boost::asio::ip::tcp::socket> socket_opt
并且在运行时具有值。
boost::asio::read_until()
需要动态缓冲区作为第二个参数。
我希望下面的代码能帮助你。
boost::asio::streambuf buf;
boost::asio::read_until(this->socket_opt.value(), buf, "n");