[英]When performing an async_write with a tcp socket, when is the handler called?
This is just a simple question of how async_write behaves with tcp sockets. 这只是async_write如何与tcp套接字一起运行的简单问题。 Basically, when working with a tcp socket, does the write handler get called when the data gets written to the socket, or when an ack is received from the destination? 基本上,当使用tcp套接字时,在将数据写入套接字时,或者从目标接收到ack时,是否会调用写入处理程序?
AFAIK,只要数据写入套接字的内核缓冲区,就会调用处理程序。
Same behavior as the BSD socket's send()
- it completes when the OS has a copy of the data. 与BSD套接字的send()
行为相同 - 它在操作系统具有数据副本时完成。 This will be before an ACK. 这将在ACK之前。
The only guarantee provided by Boost.Asio is that the handler will be called when the operation completes. Boost.Asio提供的唯一保证是在操作完成时将调用处理程序。 In the case of async_write
, the operation is considered complete when any of the following are true: 对于async_write
,如果满足以下任何条件,则认为操作已完成:
socket_.cancel()
. socket_.cancel()
。 Once the operation completes, the handler is posted for deferred invocation. 操作完成后,将发布处理程序以进行延迟调用。 However, it is unspecified as to exactly when and the order in which handlers will be invoked. 然而,它是不确定的, 究竟何时在处理程序将被调用的顺序。 Consider the scenario where an async_write
operation has been initiated for 2 different sockets. 考虑已为2个不同套接字启动async_write
操作的方案。 Any of the following sequences are possible: 以下任何序列都是可能的:
async_write
operation 1 completes. async_write
操作1完成。 async_write
operation 2 completes. async_write
操作2完成。 async_write
operation 1 completes. async_write
操作1完成。 async_write
operation 2 completes. async_write
操作2完成。 async_write
operation 1 completes. async_write
操作1完成。 async_write
operation 2 completes. async_write
操作2完成。 I think you need high layer protocals. 我认为你需要高层原型。 if a remote peer program blows your request package, ACK is also does not fit your need. 如果远程对等程序打破了您的请求包,则ACK也不适合您的需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.