将HttpApi与I / O完成端口配合使用 [英] Using HttpApi with I/O Completion Ports

查看:91
本文介绍了将HttpApi与I / O完成端口配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现微软的 HTTP Server API 。介绍声明:

I've just stumbled upon Microsoft's HTTP Server API. The introduction states:


HTTP Server API使应用程序能够通过HTTP进行通信,而无需使用Microsoft Internet Information Server(IIS)。应用程序可以注册以接收特定URL的HTTP请求,接收HTTP请求以及发送HTTP响应。 HTTP Server API包括SSL支持,以便应用程序可以在没有IIS的情况下通过安全HTTP连接交换数据。 它还可以与I / O完成端口一起使用。

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

Finding this cool, I took a long hard look at the list of functions for both versions of the API. Now, the only other part of the documentation that mentions I/O completion ports is the HttpReceiveHttpRequest() function. The last parameter is an optional OVERLAPPED structure with the following description:


对于异步调用,请设置 pOverlapped 指向 OVERLAPPED 结构;对于同步调用,将其设置为 NULL 。同步调用将阻塞,直到请求已到达指定队列并且已检索到部分或全部请求,而异步调用会立即返回 ERROR_IO_PENDING ,然后调用应用程序将使用 GetOverlappedResult() 或I / O完成端口,以确定操作何时完成。有关使用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 Synchronization and Overlapped Input and Output.

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

There is no other information, and all structures are opaque and deliberately hide connection information. Also notice that the Synchronization and Overlapped Input and Output subject makes no mention of the HTTP API.

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

Does anyone have any idea on how to connect the HTTP API's queue to an I/O completion port?

推荐答案

在理论上使用IO完成端口非常简单,但是很容易理解练习:P

Using IO completion ports is trivially simple in theory, but abomnible in practice :P

正常用法是:


  1. 调用CreateIOCompletionPort到创建一个IO完成端口句柄。

  2. 创建一堆线程,并在调用GetOverlappedResult时让每个线程循环。当与端口关联的重叠操作完成时,GetOverlappedResult将返回,其中结构指示哪个句柄和操作已完成。

  3. 在程序运行时,创建它希望异步处理的对象,它通过再次调用CreateIOCompletionPort将每个HANDLE与IO CompletionPort句柄相关联。

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

Now, each time the application issues an asynchronous operation on the HANDLE (which is signalled by passing in an OVERLAPPED struct) the notification of the completed operation will be indicated by one of the threads thats waiting on GetOverlappedResult returning.

明确的含义是由HttpCreateRequestQueue返回的HANDLE可以与IO完成端口关联,后续的异步操作将导致GetOverlappedResult返回操作的结果。

The clear implication is that the HANDLE returned by HttpCreateRequestQueue can be associated with an IO Completion port and subsequent asynchronous operations will result in GetOverlappedResult's returning the result of the operation.

这篇关于将HttpApi与I / O完成端口配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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