EOF in async_read() in boost::asio

一曲冷凌霜 提交于 2019-12-30 05:59:08

问题


When the async_read_some() returns an exception of EOF does it mean the server stopped sending data or does it mean the connection is closed. I'm having this confusion as I cant find a method to know if the client has received all data from server.


回答1:


It indicates the connection has closed. Although documented elswhere it is still applicable:

An error code of boost::asio::error::eof indicates that the connection was closed by the peer.

If a client needs to know that all data has been received from the server, then consider supporting framing in the communication protocol. Boost.Asio provides higher-level operations to help make this easier. For example async_read_until() can be used on protocols where a certain set of characters are used to indicate the end of a message, and async_read() can be used for either fixed-length protocols or variable length protocols with a fixed length header.



来源:https://stackoverflow.com/questions/15297001/eof-in-async-read-in-boostasio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!