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

前端之家收集整理的这篇文章主要介绍了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返回操作的结果.

原文链接:https://www.f2er.com/windows/364977.html

猜你在找的Windows相关文章