boost :: asio中的async_read()中的EOF [英] EOF in async_read() in boost::asio

查看:183
本文介绍了boost :: asio中的async_read()中的EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当async_read_some()返回EOF的异常时,这意味着服务器停止发送数据,或者意味着连接关闭。我有这个困惑,因为我找不到一个方法来知道客户端是否已收到来自服务器的所有数据。

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.

推荐答案

这表示连接已关闭。虽然记录的 elswhere 仍然适用:

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


错误代码 boost :: asio :: error :: eof 连接被对等体关闭。

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

如果客户端需要知道已从服务器接收到所有数据,请考虑在通信协议中支持成帧。 Boost.Asio提供更高级的操作,以帮助使这更容易。例如, async_read_until()可用于以下协议:某些字符集用于表示消息的结束,并且 async_read ()可用于固定长度协议或具有固定长度标头的可变长度协议。

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.

这篇关于boost :: asio中的async_read()中的EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆