gpt4 book ai didi

c++ - boost.asio 套接字接收/发送功能不好吗?

转载 作者:可可西里 更新时间:2023-11-01 18:37:21 25 4
gpt4 key购买 nike

Data may be read from or written to a connected TCP socket using the receive(), async_receive(), send() or async_send() member functions. However, as these could result in short writes or reads, an application will typically use the following operations instead: read(), async_read(), write() and async_write().

我真的不明白 read()、async_read()、write() 和 async_write() 也可以以短写或短读结束,对吗?
为什么这些功能不一样?
我应该使用它们吗?
有人可以为我澄清一下吗?

最佳答案

readasync_readwriteasync_write组合函数多次调用类函数,直到传输了请求的字节数。为方便起见,它们被图书馆收录。否则,每个开发人员都需要实现相同的逻辑。

类函数直接包装了底层操作系统函数,基本上在文档中声明:这些函数可能会在所有字节传输之前返回。

在大多数情况下,您应该使用自由(组合)函数来传输数据。

关于c++ - boost.asio 套接字接收/发送功能不好吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2861523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com