当超过两次下载正在进行时 HttpSendRequest 阻塞

发布于 2024-08-11 00:42:01 字数 708 浏览 6 评论 0原文

在我们的程序中,每次需要发出HTTP请求时都会创建一个新线程,并且可以有多个线程同时运行。我遇到的问题是,如果我已经有两个线程正在运行,它们在调用 HttpSendRequest() 后循环读取 InternetReadFile() ,任何后续的线程尝试调用 HttpSendRequest() 只会挂起该调用,因此我最终会看到前面提到的两个线程继续从其连接中读取数据,但第三个线程只是阻塞在 HttpSendRequest() 上直到超时。

从我自己找到的情况来看,这似乎可能就是 wininet 的工作方式,如 HTTP 规范 建议:“单用户客户端不应与任何服务器或代理保持超过 2 个连接。”

我见过各种程序处理对同一服务器的多个同时下载,但我想他们需要做很多额外的工作才能做到这一点,在管理各种连接或编写自己的 http 接口方面。

如果需要大量额外的复杂性来将其设置为处理两个以上的活动会话,那么我只需将其更改为一次仅处理一两个文件,而将其余文件留在队列中。然而,如果有一些低复杂性的方法允许一次超过两个(我想,我猜每次下载使用一个新进程可能会起作用,但会更混乱),那就更好了;无论如何,它不会同时下载超过 3-5 个,并且每次下载都是根据用户的请求进行的。我读到一些提到注册表黑客改变限制的内容,但这绝对不是我会做的事情。有什么想法吗?

In our program, a new thread is created each time an HTTP request needs to be made, and there can be several running simultaneously. The problem I am having is that if I've got two threads already running, where they are looping on reading from InternetReadFile() after having called HttpSendRequest(), any subsequent attempts to call HttpSendRequest() just hang on that call, so I end up with the previously mentioned two threads continuing to read from their connections just fine, but the third just blocks on HttpSendRequest() until it times out.

From what I've been able to find on my own, this seems like it could just be the way wininet works, as the HTTP spec recommends: "A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy."

I've seen various programs handle multiple simultaneous downloads to the same server, but I'd imagine they need to do a lot of extra work to do that, in terms of managing the various connections, or writing their own http interface.

If it would require a lot of extra complexity to set it up to handle more than two active sessions, then I would just change things to only handle one or two files at a time, leaving the rest queued. However, if there were some low-complexity way to allow more than two at a time (off the top of my head, I'd guess using a new process per download might work, but would be messier), that would be preferable; it's not like it would be downloading more than 3-5 simultaneously anyway, and each download is at the user's request. I read some mentions of registry hacks to change the limit, but that's definitely not something I'd do. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

机场等船 2024-08-18 00:42:01

HTTP 1.1 标准要求每台服务器最多同时存在 2 个连接。如果您安装了 IE5、IE6 或 IE7,它们安装的 WinInet 版本允许您使用 InternetSetOption() 来增加限制(查看 INTERNET_OPTION_MAX_CONNS_PER_SERVER 和 INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER 选项)。但是,随 IE8 安装的 WinInet 版本显然禁用了该功能(请参阅 http://connect.microsoft.com/WNDP/feedback/ViewFeedback.aspx?FeedbackID=434396http://connect.microsoft.com/WNDP/feedback/ViewFeedback.aspx?FeedbackID=481485)。

The HTTP 1.1 standard mandates a maximum of 2 simultaneous connections per server. If you have IE5, IE6, or IE7 installed, the versions of WinInet they install allow you to use InternetSetOption() to increase the limit (look at INTERNET_OPTION_MAX_CONNS_PER_SERVER and INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER options). However, the version of WinInet that is installed by with IE8 apparently disables that functionality (see http://connect.microsoft.com/WNDP/feedback/ViewFeedback.aspx?FeedbackID=434396 and http://connect.microsoft.com/WNDP/feedback/ViewFeedback.aspx?FeedbackID=481485).

一紙繁鸢 2024-08-18 00:42:01

如果多次调用 InternetOpen(),您应该能够在 InternetOpen() 返回的每个 HINTERNET 上同时下载两个文件。

If you call InternetOpen() multiple times, you should be able to simultaneously download two files on each HINTERNET returned by InternetOpen().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文