I've read that you can use boost::asio::read_until
to read from a socket, so I tried to do that:
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:
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.
boost::asio::read_until()
requires dynamic buffer as second parameter.
I hope the following code helps you.
boost::asio::streambuf buf;
boost::asio::read_until(this->socket_opt.value(), buf, "\n");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.