c++ - 提升 asio receive() 与 read()

标签 c++ tcp boost-asio

boost::asio::ip::tcp::socket 有两种读取流的函数。我假设他们的语义不同。有人可以概述一下吗,我有文档 looked through没有澄清这一点。

最佳答案

正如文档中所说:

The receive() operation may not receive all of the requested number of bytes. Consider using the read() function if you need to ensure that the requested amount of data is read before the blocking operation completes.

如果您实际上是指 read_some(),则没有区别。 receive() 是特定于套接字的函数,而 read_some() 是可用于所有 asio 流的通用函数。 (很像 std::stringlength()size())

关于c++ - 提升 asio receive() 与 read(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6733425/

相关文章:

c++ - std::set 中的自定义仿函数

c++ - C++11 中的线程安全单例

networking - 当 Dup Ack 到达时,TCP 是否会增加其拥塞窗口?

linux - "Compiler threading support is not turned on."

c++ - 在 linux 中使用另一个共享库构建共享库

c++ - 从 vector 中删除时 vector 迭代器不兼容

c# - 对于我必须连接到服务器的每个 Tcp 连接,我如何单独管理每个连接?

java - Android TCP 客户端/服务器未正确传递消息(仅首次收到)

C++ 提升 asio tcp 套接字读取旧数据

boost - 为什么 boost 示例再次调用 `shared_from_this()` 而不是使用闭包变量