This is just a simple question of how async_write behaves with tcp sockets. 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?
AFAIK,只要数据写入套接字的内核缓冲区,就会调用处理程序。
Same behavior as the BSD socket's send()
- it completes when the OS has a copy of the data. This will be before an ACK.
The only guarantee provided by Boost.Asio is that the handler will be called when the operation completes. In the case of async_write
, the operation is considered complete when any of the following are true:
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. Any of the following sequences are possible:
async_write
operation 1 completes. async_write
operation 2 completes. async_write
operation 1 completes. async_write
operation 2 completes. async_write
operation 1 completes. async_write
operation 2 completes. I think you need high layer protocals. if a remote peer program blows your request package, ACK is also does not fit your need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.