Re: Wininet Timeouts
From: Andrew Trevarrow (andrew_at_andrewt-nospam-.com)
Date: 07/19/04
- Next message: Darren Beckley: "Re: how to stop the irda application?"
- Previous message: The PocketTV Team: "any way to access localized string for Yes, NO, OK, Cancel etc ?"
- In reply to: Nikki Casali: "Wininet Timeouts"
- Messages sorted by: [ date ] [ thread ]
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
>
- Next message: Darren Beckley: "Re: how to stop the irda application?"
- Previous message: The PocketTV Team: "any way to access localized string for Yes, NO, OK, Cancel etc ?"
- In reply to: Nikki Casali: "Wininet Timeouts"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|