c++ - boost::asio::async_read get end of file error -
i've written program uses boost:asio library, transfers data between 2 tcp servers. 1 server uses following code send data:
std::shared_ptr<std::string> s = std::make_shared<std::string>(message); boost::asio::async_write(socket_, boost::asio::buffer(*s), std::bind(&tcpserver::handlewrite, shared_from_this(), s, _1, _2));
in tcpserver, when use async_read_until data, works fine, if replace async_read_until async_read, gives end of file
error:
boost::asio::streambuf input_buffer; boost::asio::async_read_until(socket_, input_buffer, match_condition(), std::bind(&tcpserver::handleread, shared_from_this(), _1)); //boost::asio::async_read(socket_, input_buffer, boost::asio::transfer_all(), // std::bind(&tcpserver::handleread, shared_from_this(), _1));
if use boost::asio::transfer_at_least(1)
in async_read, can expected result.
why did happen?
an eof error indicates writer side closed connection. data sent before should still available in tcpserver::handleread
callback. check bytes_transferred
parameter find out how data received reader.
Comments
Post a Comment