W3C home > Mailing lists > Public > www-lib@w3.org > April to June 2000

Infinite Event Loop

From: Yovav Meydad <yovavm@contact.com>
Date: Thu, 13 Apr 2000 20:01:38 +0200
To: <www-lib@w3.org>
Message-ID: <002301bfa572$511e0580$1c44a8c0@yovavm>
Hi,

I have a GUI app, which makes a call to a COM object's method which should
perform a file download from some URL.
I have a C++ class which wraps some of libwww functions, and in the COM
object's implementation I use an instance of this class in order to actually
perform the download.
The implementation of the Download method is based on the Loadtofile sample
of libwww.

So, I implemented the DownloadFile method; the filters for Progress &
Messages
and a terminate handler which is an AFTER filter for the download request I
create.

Note:
I use Win2K & DevStudio 6.0 sp3

The problem :
~~~~~~~~~~~
After calling to HTLoadToFile, I enter the event loop.
During the Dispatching of the message by the loop, a 2nd thread is created,
Which in it the PROGRESS handler & Terminate handlers are done.
But, after the terminate handler is finished, the context returns to the
message loop of the GUI, instead to the 1st thread.
After a while (several min.), some timeout occurs, and the event loop gets
another message to handle.
Since I have inserted in TerminateHandler a call to HTEventList_stopLoop(),
the boolean flag of the loop set to 1, and the loop is stopped.
After this, the context goes back to the COM object method, then I can
continue checking the status etc.

How can I cause the context to return to the 1st thread immediately after
the TerminateHandler is done ? Why does it happen ?
In all other samples of libwww including WinCom only 1 thread is created -
why is this ?

Here are some parts from the code:
~~~~~~~~~~~~~~~~~~~~~~~
1. The download method of the COM object:

STDMETHODIMP CAutoUpgrader::DownloadUpgrade()
{
	// Some code to obtain the url, host, port, fileName
	...

	CRequester requester;
	st = requester.RequestDownload(lpHost, iPort, const char *i_lpURL, const
char *i_lpOutputFile

	// Check download statu
	if (!st)
		// Error
	return S_OK;
}

2. The requester is a C++ class, which wraps some libwww code:

int CRequester::RequestDownload(const char *i_lpHost, int i_iPort, const
char *i_lpURL, const char *i_lpOutputFile)
{
	// Create a request
	HTRequest* pRequest = HTRequest_new();

    	// register the Download Termination handler
	HTRequest_addAfter(pRequest,TerminateHandler,NULL, NULL, HT_ALL,
HT_FILTER_FIRST, YES);

	// construct a string with full url
	string strURL = createFullUrl(i_lpHost, i_iPort, i_lpURL);

	// Download it
	BOOL st = HTLoadToFile(strURL.c_str(), pRequest, i_lpOutputFile);

        	// Go into the event loop...
	HTEventList_newLoop();

}

3. I also implemented the filter for HT_A_PROGRESS and HT_A_MESSAGE,
which posts messages to the GUI regarding progress & errors.

4. In the TerminateHandler I perform:

BOOL TerminateHandler(HTRequest * request, HTResponse * response, void *
param, int status)

	// cleanup the request & stop the event loop
	HTRequest_delete(request);
	HTEventList_stopLoop();
 	return (status ? status : HT_OK);
}

Hope someone has the answer,

thanks
Yovav

~~~~~~~~~~~~~~~~~~~
yovavm@contact.com

Software Engineer
Contact Networks
www.contact.com
We Invite You to Make Contact!
~~~~~~~~~~~~~~~~~~~
Received on Thursday, 13 April 2000 14:02:48 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:36 GMT