When using IOCP, if I call WSASend()
with let's say 2 KB of data. When I receive a completion notification, will this completion notification indicate that the entire 2 KB were sent, or there could be some bytes that were not sent?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Under normal circumstances, yes, your completion will receive notification that the entire 2 KB was sent, as long as the socket is using overlapped I/O.
The only scenario where it may return less than the size of the data sent is when the connection is terminated in the middle of a send; in this case, it returns the partial number of bytes sent.
If it's not using overlapped I/O, it can return a partial write if the transport buffers don't have enough space to receive your entire write.
In my experience, this case is rarely handled, as the connection being terminated will usually invoke some other error handling, and there is rarely anything useful you can do with the number of bytes sent.