当我调用WSASend()时,是否将发送所有数据? [英] When I call WSASend(), will all the data be sent?

查看:92
本文介绍了当我调用WSASend()时,是否将发送所有数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用IOCP时,如果我调用WSASend()并假设有2 KB数据.当我收到完成通知时,此完成通知会表明已发送了整个2 KB,还是可能有一些未发送的字节?

解决方案

在正常情况下,是的,只要套接字使用重叠的I/O,您的完成操作就会收到有关已发送整个2 KB的通知.

唯一可能返回小于发送数据大小的情况是在发送中间终止连接时;在这种情况下,它将返回发送的部分字节数.

如果未使用重叠的I/O,则在传输缓冲区没有足够的空间来接收整个写入的情况下,它可以返回部分写入.

根据我的经验,这种情况很少处理,因为终止连接通常会调用其他错误处理,并且对于发送的字节数,您几乎无用.

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?

解决方案

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.

这篇关于当我调用WSASend()时,是否将发送所有数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆