kyuseo의 게임 프로그래밍

InternetSetOption의 Set Timeout 옵션 버그 본문

C++ 개발

InternetSetOption의 Set Timeout 옵션 버그

kyuseo 2007. 11. 3. 16:00

개요..

 

인터넷 관련 프로그래밍에서 인터넷 핸들(HINTERNET)을 세부적으로 세팅하는 InternetSetOption 함수에서, 인터넷 접속이 올바르지 않거나 오랜 시간이 소요될 경우 접속 및 다운로드를 중단하는 처리를 할 경우가 많습니다.

 

MSDN 에 정의된 것처럼 InternetSetOption 함수의 옵션 중 INTERNET_OPTION_CONNECT_TIMEOUT, INTERNET_OPTION_SEND_TIMEOUT 와 같은 Timeout 옵션을 이용하려 해보았지만 해당 옵션, 함수의 오류로 인하여 올바른 작동을 하지 않았습니다.

 

 

MSDN 에 정의된 함수의 모습

 

BOOL InternetSetOption(

HINTERNET hInternet,

DWORD dwOption,

LPVOID lpBuffer,

DWORD dwBufferLength

 

 

결론

 

- InternetSetOption 의 Set Timeout관련 옵션은 정상 작동하지 않습니다.

- CInternetSession CHttpConnection CHttpFile 클래스 사용시에도 주의해야 합니다.

- 접속, 다운로드, 업로드 시 매우 긴 시간 동안 지연(랙) 현상이 발생될 수 있습니다.

 

 

- 무한정 기다리게 하지 않기 위해서는

방법1.

별도의 스레드(thread) 에서 핸들을 감시하여 지연 현상이 발생된다면 연결을 끊어 Set TimeOut 관련 기능을 별도로 구현해야 합니다.

 

방법2.

별도의 스레드(thread)에서 인터넷 함수를 처리하고, 진행 스레드(thread)에서 핸들을 감시를 합니다.

 

 

MS에서 발표한 InternetSetOption 관련 버그 내용:

 

출처:http://support.microsoft.com/kb/q176420/

BUG: InternetSetOption does not set timeout values

View products that this article applies to.

Article ID

:

176420

Last Review

:

July 11, 2006

Revision

:

3.3

This article was previously published under Q176420

SYMPTOMS

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

Back to the top

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.

INTERNET_OPTION_RECEIVE_TIMEOUT no longer works in Microsoft Internet Explorer 5.0.

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

224318 (http://support.microsoft.com/kb/224318/) How to control connection timeout value by creating second thread

Back to the top

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

The latest version of the Wininet.dll file that is included with MIcrosoft Internet Explorer 5.01 fixes all time-out problems for HTTP APIs only. FTP time-outs still cannot be changed. Internet Explorer 5.01 is available for download.

Back to the top

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.

Back to the top