When I call WSASend(), will all the data be sent?

孤者浪人 提交于 2020-01-01 17:15:26

问题


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.



来源:https://stackoverflow.com/questions/28675811/when-i-call-wsasend-will-all-the-data-be-sent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!