- From: jayprakash <jayprakash@opussoft.com>
- Date: Mon, 18 Mar 2002 13:10:44 +0530
- To: <www-lib@w3.org>
Hello , 
1) is www-lib support multithread application ? 
2) can I init in one thread and post from other ? 
we have tried it but it doesn't seems to be working . 
if we init in one thread then all the post from that thread works. 
but from other thread it blocks in event loop GetMesssage
waiting for reply .....
Thanks and Regards 
Jai 
////////////////////////////////
bool gIsDone = false ; 
DWORD WINAPI ThreadCheck(  LPVOID lpParameter ) 
{
	if ( ! gIsDone ) 
	{
		WaitForSingleObject( ( HANDLE ) lpParameter, INFINITE ) ;
	}
	CoInitialize(NULL);
	double lStartTime = GetTime();		
	long i = 0 ; 
	do 
	{
	    /* Create a new premptive client */
	    HTProfile_newNoCacheClient("HTTPTest", "1.0");		
	    /* Add our own filter to handle termination */	
	    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
	
	    HTHost_setEventTimeout(20000);
	
	    // Delete all Registered proxies in libwww
	    HTProxy_deleteAll();
	    HTNoProxy_deleteAll();
	
	    // regex for what to proxy
	    HTProxy_addRegex("http://www.", "http://192.200.8.20:80", -1);
	
	    // regex for what not to proxy
	    HTNoProxy_addRegex("http://localhost", -1);
	
	    /* Initialize libwww */
	    //HTProfile_newPreemptiveClient("HTTPTest ", "1.1");
		
		char * lData = "2=dataforpostTEST";
		HTAssocList * formfields = HTAssocList_new();
		HTParseFormInput(formfields, lData);
		char * cwd = HTGetCurrentDirectoryURL();
		char * dst_str = "http://192.200.8.252/default.asp?1=Dataforget=hi" ;
		HTAnchor * dst = HTAnchor_findAddress(dst_str);
	
		HTRequest * lrequest  = HTRequest_new(); 
		
	
		HTRequest_setOutputFormat(lrequest, WWW_SOURCE);
	
		HTChunk * chunk = HTPostFormAnchorToChunk(formfields, dst, lrequest);
	
		if (chunk) 
		{
			char * string;
			//Go into the event loop... 
			HTEventList_loop(lrequest);
		
			// print the chunk result 
			string = HTChunk_toCString(chunk);
		
			AfxMessageBox(string);
		
			HT_FREE(string);
		}
		else 
		{
			AfxMessageBox("Type the URL you want to accces on the command line\n");
	      }
		/* Clean up the form fields */
		HTAssocList_delete(formfields);
	
	    HTRequest_delete(lrequest);
	
	    /* Terminate the Library */
	    //HTProfile_delete();
	
	
	    /* Terminate the Library */
		 HTLibTerminate();
		i++ ;
	}
	while(i < 1  ) ; 
	
	double lEndTime = GetTime();
	double lDiff = ( lEndTime - lStartTime ) / 1000;
	char lDiffStr[30] = "\0";
	sprintf( lDiffStr, "%20.3f", lDiff );
	AfxMessageBox(lDiffStr ) ; 
	return 0;
}
void CTestDlg::OnThreadTest() 
{
	UpdateData() ; 
	
	HANDLE lHandle = NULL;
	DWORD  lThreadId = 0;
	HANDLE	hEvent = NULL ;
	hEvent = CreateEvent( NULL, TRUE, FALSE, "StartThreadCheck" );
	int i =  0 ; 
	do 
	{
		lHandle = CreateThread( NULL, 0, ThreadCheck, NULL, 0, &lThreadId );	
		i ++ ; 
	}
	while( i < 1 ) ; 
	
	gIsDone = true ; 
	SetEvent(hEvent) ; 
	
}
Received on Monday, 18 March 2002 02:40:13 UTC