Re: Wininet Timeouts

From: Andrew Trevarrow (andrew_at_andrewt-nospam-.com)
Date: 07/19/04


Date: Mon, 19 Jul 2004 13:00:50 +0100

Nikki,

I use the wininet functions directly (rather than the MFC wrappers), and
AFAIK the call to read should complete if the internet connection is lost.

However, in wininet land I timeout connections by spinning another
thread to do the connection and, if it hasn't completed within n seconds
I close the internet handle causing the connect to complete (and fail).

--
HINTERNET hOpenUrl;
HINTERNET hSession;
HINTERNET Open()
{
	hSession = InternetOpen();
	HANDLE hOpenThread = CreateThread(OpenThreadProc)
	if (WaitForSingleObject(hOpenThread, TIMEOUT_PERIOD) != WAIT_OBJECT_0)
	{
		InternetCloseHandle(hSession);
		WaitForSingleObject(hOpenThread, INFINITE);
		hOpenUrl = NULL;
	}
	return hOpenUrl;
}
OpenThreadProc()
{
	hOpenUrl = InternetOpenUrl(hSession, ...);
}
--
(See this MSDN article for more info: 
http://support.microsoft.com/default.aspx?scid=kb;en-us;224318)
This definitely works for creating the connection, not sure if the same 
principal works for InternetReadFile. I'm also not sure how this will 
work with CInternetFile as MFC classes are notoriously not threadsafe.
HTH.
Andrew.
Nikki Casali wrote:
> Does anyone know a way to timeout CInternetFile::Read if the Internet 
> connection is lost?
> 
> You can call CInternetSession with the INTERNET_FLAG_ASYNC flag and 
> timeout from another thread, but there is no documentation on how to 
> implement this. In fact, the documentation is looking rather fanciful.
> 
> I'm thinking maybe of creating a CWinThread to execute 
> CInternetFile::Read and killing the thread if it takes too long.
> 
> Any ideas?
> 
> Nikki
> 


Relevant Pages

  • Re: What does the "Configure email and Internet Connection Wizard"
    ... > the CEICW does (listed under "Configure Email and Internet Connection ... > Configure E-mail and Internet Connection Wizard is designed to correctly ... > configure settings for your network, firewall, secure Web site, and e-mail ...
    (microsoft.public.windows.server.sbs)
  • Re: What does the "Configure email and Internet Connection Wizard"
    ... Understanding the Configure E-mail and Internet Connection WizardThe ... Configure E-mail and Internet Connection Wizard is designed to correctly ... configure settings for your network, firewall, secure Web site, and e-mail ...
    (microsoft.public.windows.server.sbs)
  • Re: Serious Security Issue in Windows XP SP2s Firewall
    ... Subject: AW: Serious Security Issue in Windows XP SP2's Firewall ... If you update a WinXP SP-1 with enabled Internet ... Connection Firewall ...
    (Focus-Microsoft)
  • Re: Fixing or REPLACING I.E.6
    ... Also, it may be that your connection setups need to be adjusted, as in, ... been idle while on the Internet. ... This is referred to as the Idle Disconnect ... Download the newest version of HiJackThis here: ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Working LAN, but no client Internet -Again
    ... For symptoms that concern Internet connectivity, ... My laptops have always been able to make it out and ping everything on my ... I can get the network connection details and they are the ...
    (microsoft.public.windowsxp.network_web)