IOCP:内核如何决定同步或异步完成WSASend? [英] IOCP: how does the kernel decide to complete WSASend synchronously or asynchronously?

查看:311
本文介绍了IOCP:内核如何决定同步或异步完成WSASend?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们编写了利用I/O完成端口并在SOCKET对象上使用WSASend,在命名管道上使用WriteFile的软件.

We wrote software that leverages I/O Completion Ports, and uses WSASend on SOCKET objects, WriteFile on named pipes.

在两种情况下,我们都发现这些API比我们预期的要早得多(或与命名管道的WriteFile操作等效)返回SOCKET_ERROR/WAS_IO_PENDING [1].

In both situations we are finding that those APIs return SOCKET_ERROR / WAS_IO_PENDING [1] a lot sooner than we expected (or the equivalent for a named pipe WriteFile operation).

似乎我们错误地认为,如果我们填充了发送缓冲区(CreateNamedPipe中的nInBufferSize),则异步完成将触发,相反,它似乎更具攻击性,并且与发送缓冲区的大小无关.对于套接字和命名管道,如果足够快,那么大的发送缓冲区(100k +)和小消息(几个字节)将始终在第二次写入时异步完成.

It seems we have wrongly assumed that asynchronous completion would trigger if we fill up the send buffer (nInBufferSize in CreateNamedPipe), instead it seems to be a lot more aggressive and unrelated to the size of the send buffer. For both sockets and named pipes, a large send buffer (100k+) and small messages (a few bytes) will always be completed asynchronously on the second write if done fast enough.

任何人都可以确认吗?是否有人了解Windows实施在决定何时异步完成I/O操作(而不是同步完成)时遵循的启发式方法?

Can anyone confirm this? Does anyone have information on the heuristics that the Windows implementation follows in deciding when to complete I/O operations asynchronously, versus doing a synchronous completion?

[1]如果重叠操作成功启动并且将在以后完成,则WSASend返回SOCKET_ERROR并指示错误代码WSA_IO_PENDING. - http://msdn.microsoft .com/en-us/library/windows/desktop/ms742203(v = vs.85).aspx

[1] "If the overlapped operation is successfully initiated and will complete later, WSASend returns SOCKET_ERROR and indicates error code WSA_IO_PENDING." - http://msdn.microsoft.com/en-us/library/windows/desktop/ms742203(v=vs.85).aspx

推荐答案

为什么您认为需要了解或关心.它不是API的文档化部分,它可能会受到当时驱动程序和堆栈中任何分层服务提供者的影响.

Why do you think you need to know or care. It's not a documented part of the API and it's possibly affected by the drivers and any layered service providers in the stack at the time.

您必须编写正确的代码来处理成功的同步"发送或未决的异步"发送,所以这使您获得两种结果的频率有何不同?

You have to write the correct code to handle either a successful 'synchronous' send or a pending 'asynchronous' send so what difference does it make how often you get either kind of result?

此外,除非您使用的是 SetFileCompletionNotificationModes()以启用FILE_SKIP_COMPLETION_PORT_ON_SUCCESS相同的代码路径用于同步结果和挂起的结果.

Also, unless you are using SetFileCompletionNotificationModes() to enable FILE_SKIP_COMPLETION_PORT_ON_SUCCESS the same code path is used for both sync and pending results.

这篇关于IOCP:内核如何决定同步或异步完成WSASend?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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