CInternetSession设置超时无效

转贴自:http://www.softwelt.com/Know/KnowDetail-2870437.html


问题:CInternetSession设置超时?
m_pSession = new CInternetSession();
m_pSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5000);


但是发现后面使用CHttpFile和CHttpConnection连接的时候,
超时时间还是很久,不是5000毫秒

请问这个问题怎么解决?

提问时间: 2005-2-18 10:39:56 回答次数: (5) 提问人: 软界网友  我来回答
回答(1)
BUG: InternetSetOption Does Not Set Timeout Values
ID: Q176420


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft ActiveX SDK, version 1.0
Internet Client SDK, versions 4.0, 4.01
Microsoft Internet Explorer (Programming) version 5

--------------------------------------------------------------------------------


SYMPTOMS
Calling InternetSetOption (or MFC CHttpFile::SetOption) with INTERNET_OPTION_SEND_TIMEOUT or INTERNET_OPTION_CONNECT_TIMEOUT does not set the specified timeout values.



RESOLUTION
To work around the problem you can use asynchronous WinInet mode, which prevents the WinInet function call from blocking while waiting for a connection. Please see the Internet Client SDK documentation for more information about using WinInet asynchronously.

Another solution may be to create a second thread that would call blocking WinInet API. Closing the handle from within the original thread will cancel blocking API in the second thread. Please see documentation for InternetCloseHandle for more details.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



MORE INFORMATION
InternetSetOption works for INTERNET_OPTION_RECEIVE_TIMEOUT. The receive timeout option controls how long to wait for incoming data to become available. It does not control how long to wait while connecting to or sending data to the server. If the network is down or the server is not available, a WinInet function call that makes a connection (HttpSendRequest, for example) can potentially block for a long time.

NOTES:

INTERNET_OPTION_RECEIVE_TIMEOUT no longer works in Internet Explorer 5.0. For more information, see the following article in the Microsoft Knowledge Base:


Q224318 HOWTO: Control Connection Timeout Value by Creating Second Thread
The latest version of the Wininet.dll file that shipped with Internet Explorer 5.01 (available for download) fixes all timeout problems for HTTP APIs only. FTP timeouts still cannot be changed.


© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Leon Braginski, Microsoft Corporation


Additional query words:

Keywords : kbSDKInet400 kbSDKInet401 kbIE500bug
Version : WIND
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值