微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

windows – 使用带有I / O完成端口的HttpApi

我刚刚偶然发现了微软的 HTTP Server API.介绍说:

The HTTP Server API enables applications to communicate over HTTP without using Microsoft Internet information Server (IIS). Applications can register to receive HTTP requests for particular URLs,receive HTTP requests,and send HTTP responses. The HTTP Server API includes SSL support so that applications can exchange data over secure HTTP connections without IIS. It is also designed to work with I/O completion ports.

找到这个很酷的,我仔细查看了两个版本的API的功能列表.现在,文档中提到I / O完成端口的唯一其他部分是HttpReceiveHttpRequest()功能.最后一个参数是可选的OVERLAPPED结构,具有以下描述:

For asynchronous calls,set pOverlapped to point to an OVERLAPPED structure; for synchronous calls,set it to NULL. A synchronous call blocks until a request has arrived in the specified queue and some or all of it has been retrieved,whereas an asynchronous call immediately returns ERROR_IO_PENDING and the calling application then uses GetoverlappedResult() or I/O completion ports to determine when the operation is completed. For more information about using OVERLAPPED structures for synchronization,see 07003.

没有其他信息,所有结构都是不透明的,故意隐藏连接信息.另请注意,同步和重叠输入和输出主题未提及HTTP API.

有没有人知道如何将HTTP API的队列连接到I / O完成端口?

在理论上使用IO完成端口非常简单,但在实践中却很难实现:P

“正常”用法是:

>调用CreateIOCompletionPort以创建IO完成端口句柄.
>创建一堆线程,并在调用GetoverlappedResult时让每个线程循环.当与端口关联的重叠操作完成时,GetoverlappedResult将返回,其中结构指示完成了哪个句柄和操作.
>当您的程序运行并创建它希望异步处理的对象时,它会通过再次调用CreateIOCompletionPort将每个HANDLE与IO CompletionPort句柄相关联.

现在,每次应用程序在HANDLE上发出异步操作时(通过传入OVERLAPPED结构信号),完成操作的通知将由等待GetoverlappedResult返回的其中一个线程指示.

明确的含义是HttpCreateRequestQueue返回的HANDLE可以与IO Completion端口关联,后续的异步操作将导致GetoverlappedResult返回操作的结果.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐