具有多个缓冲区的 WSASend() - 可能会不完整?
假设我发布以下 WSASend 调用(没有回调函数的 Windows I/O 完成端口):
void send_data()
{
WSABUF wsaBuff[2];
wsaBuff[0].len = 20;
wsaBuff[1].len = 25;
WSASend(sock, &wsaBuff[0], 2, ......);
}
当我从完成端口收到“write_done”通知时,是否可能 wsaBuff[1] 将被完全发送(25 字节)但 wsaBuff [0] 将仅部分发送(例如 7 个字节)?
Say I post the following WSASend call (Windows I/O completion ports without callback functions):
void send_data()
{
WSABUF wsaBuff[2];
wsaBuff[0].len = 20;
wsaBuff[1].len = 25;
WSASend(sock, &wsaBuff[0], 2, ......);
}
When I get the "write_done" notification from the completion port, is it possible that wsaBuff[1] will be sent completely (25 bytes) yet wsaBuff[0] will be only partially sent (say 7 bytes)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如我之前所说,在回答您的其他非常相似的问题之一时,唯一可能失败的情况是在资源不足的情况下(最有可能是非分页池或锁定页面限制问题),您可能会得到部分完成并返回 ENOBUFS 错误。再说一遍,正如我之前所说,在 10 年的 IOCP 开发工作中,我从未将其视为生产中的问题,只有在我们对系统进行压力测试至死的情况下(实际上有时是非分页的)池耗尽有时会导致行为不当的司机蓝屏盒子)。
我建议您只需添加一些代码来记录失败,关闭套接字,就这样,您已经处理了失败的可能性并可以继续前进。如果您的故障处理代码被执行过,我会感到惊讶。但您可以确信,您会知道是否是这样,并且一旦您可以重现该问题,您就可以花更多时间思考是否确实需要更好地处理它。
As I've said before, in a reply to one of your other very similar questions, the only time this is likely to fail is in low resource situations (non-paged pool or locked pages limit issues most likely) where you might get a partial completion and an error return of ENOBUFS. And again, as I've said before, in 10 years of IOCP development work I've never seen this as a problem in production, only in situations where we have been stress testing a system to death (quite literally sometimes as non-paged pool exhaustion can sometimes cause badly behaved drivers to blue screen the box).
I would suggest that you simply add some code to log the failure, close the socket and that's it, you've dealt with the possibility of the failure and can move on. I'd be surprised if your failure handling code is ever executed. But you can be confident that you'll know if it is and once you can reproduce the issue you can spend more time thinking about if you really need to handle it any better.
由于 WSASend 是执行重叠套接字 IO 的首选方式,因此如果它在不完整的情况下完成则没有任何意义 - 完成通知/例程/事件是应用程序清理/回收套接字的唯一方法。使用的结构。
另外:不,这是不可能的,无论使用什么缓冲区,单个
WSASend
调用仍然是单个 IO 调用。As
WSASend
is the preferred way of doing overlapped socket IO, it would not make any sense if it completed while incomplete - the completion notification/routine/event is the only way for the application to cleanup/recycle the used structures.Also: NO, it's not possible, a single
WSASend
call is still a single IO call, regardless of the buffers used.