简体   繁体   English

boost::asio::read_until 不接受套接字作为参数

[英]boost::asio::read_until does not accept a socket as an argument

I've read that you can use boost::asio::read_until to read from a socket, so I tried to do that:读过您可以使用boost::asio::read_until从套接字读取,所以我尝试这样做:

using namespace boost::asio;
  ...
    boost::array<char, BUFFER_SIZE> buf;
    read_until(this->socket_opt.value(), buffer(buf), "\n");

But apparently, read_until cannot accept those arguments:但显然,read_until 不能接受那些 arguments:

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");

What am I doing wrong?我究竟做错了什么?

PS socket_opt is defined as std::optional<boost::asio::ip::tcp::socket> socket_opt and has a value at runtime. PS socket_opt 被定义为std::optional<boost::asio::ip::tcp::socket> socket_opt并且在运行时有一个值。

boost::asio::read_until() requires dynamic buffer as second parameter. boost::asio::read_until()需要动态缓冲区作为第二个参数。

I hope the following code helps you.希望下面的代码对你有所帮助。

boost::asio::streambuf buf;
boost::asio::read_until(this->socket_opt.value(), buf, "\n");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM