当两个以上的下载已在进行中时,HttpSendRequest会阻塞 [英] HttpSendRequest blocking when more than two downloads are already in progress

查看:81
本文介绍了当两个以上的下载已在进行中时,HttpSendRequest会阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

根据我自己的发现,这似乎就像wininet的工作方式,如 HTTP规范建议:单用户客户端不应与任何服务器或代理保持2个以上的连接."

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."

我已经看到各种程序可以处理到同一服务器的多个同时下载,但是我想他们需要做很多额外的工作,例如管理各种连接或编写自己的http界面.

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.

如果将其设置为处理两个以上的活动会话需要大量额外的复杂性,那么我只需更改一下内容即可一次仅处理一个或两个文件,其余的则排在队列中.但是,如果有某种低复杂度的方法一次允许两个以上(我不屑一顾,我想每次下载使用一个新的过程可能会起作用,但会更麻烦),那将是更好的选择;并不是说同时下载超过3-5个,并且每次下载均应用户要求.我读过一些提到注册表黑客以更改限制的内容,但这绝对不是我要做的事情.有什么想法吗?

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?

推荐答案

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=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).

这篇关于当两个以上的下载已在进行中时,HttpSendRequest会阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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