gpt4 book ai didi

c++ - 在调用前一个完成处理程序之前异步发送数据是否有效?

转载 作者:行者123 更新时间:2023-11-28 08:16:09 25 4
gpt4 key购买 nike

我正在向 TCP 套接字异步发送数据。在上一个数据被完成处理程序报告为已发送之前发送下一个数据是否有效?

据我所知,从不同线程完成发送是不允许的。在我的例子中,所有发送都是从同一个线程完成的。

我客户端的不同模块向同一个套接字发送数据。例如。 module1 发送了一些数据,并将在调用相应的完成处理程序时继续。在此 io_service 调用 module2 的 deadline_timer 处理程序之前,这会导致另一个 async_write 调用。我应该在这里遇到任何问题吗?

最佳答案

Is it valid to send the next data piece before the previous one was reported as sent by completion handler?

不,交错写操作是无效的。这在 documentation非常清楚

This operation is implemented in terms of zero or more calls to the stream's async_write_some function, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as async_write, the stream's async_write_some function, or any other composed operations that perform writes) until this operation completes.

强调是我加的。

As I know it's not allowed when sending is done from different threads. In my case all sending are done from the same thread.

您的问题与线程无关。

关于c++ - 在调用前一个完成处理程序之前异步发送数据是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7738721/

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