[zz]Emulate event driven i/o by IOCP

[url=http://mail-archives.apache.org/mod_mbox/apr-dev/200504.mbox/%3C4265083D.2020009@wstoddard.com%3E]原文[/url]

It may be possible to use IOCompletionPorts on Windows to implement apr_pollset_*. IOCPs
aare very scalable
but moving to IOCPs will require a complete rewrite of the apr_socket implementation on Windows.
And there is
the small matter of a simple technical issue that needs to be investigated...

IOCPs support true async network i/o. BSD KQ, Solaris /dev/poll, epoll et. al. are not async,
they are event
driven i/o models. When you issue an async read on Windows, the kernel will start filling
your i/o buffer as
soon as data is available. With event driven i/o, the kernel tells you when you can do a read()
and expect to
receive data. See the difference? Your buffer management strategy will be completely different
between async
i/o and event driven i/o and I am not sure how APR (or applications that use APR) can be made
to support both
cleanly. So back to the small technial issue that needs to be investigated...

I believe (but have not verified) that it is possible to use IOCPs to emulate event-driven
network i/o. When
you make read or write calls for which you want to emulate event driven i/o, pass in a 0 length
buffer (ie,
you can manage your i/o buffers using event driven semantics). So if you issue a read passing
in a 0 length
buffer, your IOCP will get notified when there is data to read. I think :-)

Assuming the above technique works reliably, we still need to figure out how to optimize the
i/o. In general,
if there is data to read or write, synchronous calls are more efficient (if there is data
to read, then just
read it rather than telling the kernel to tell you via a notification method that there is
data to read. How
do you do that on Windows if you want to emulate event driven i/o?
阅读更多
个人分类: 网络编程
上一篇用完成端口(IOCP)实现一个简单的服务器框架
下一篇集成 IOCP 到 Libevent
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭