简体   繁体   English

提升 asio 接收()与读取()

[英]boost asio receive() vs read()

There are two types of reading-from-stream functions for boost::asio::ip::tcp::socket . boost::asio::ip::tcp::socket有两种类型的从流中读取的函数。 I am assuming they their semantics vary.我假设它们的语义不同。 Could someone please outline them, the documentation I have looked through does not clarrify this.有人可以概述它们吗,我浏览过的文档并没有澄清这一点。

As it says in the documentation:正如文档中所说:

The receive() operation may not receive all of the requested number of bytes. receive()操作可能不会接收到所有请求的字节数。 Consider using the read() function if you need to ensure that the requested amount of data is read before the blocking operation completes.如果您需要确保在阻塞操作完成之前读取请求的数据量,请考虑使用read() function。

If you actually meant read_some() , then there is no difference.如果您实际上是指read_some() ,那么没有区别。 receive() is the socket-specific function, whereas read_some() is the generic function available for all asio streams. receive()是特定于套接字的 function,而read_some()是可用于所有 asio 流的通用 function。 (much like std::string 's length() and size() ) (很像std::stringlength()size()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM