- From: Mahesh Shankar <mahesh@iptechniques.com>
- Date: Thu, 22 Jul 2004 16:46:34 -0700
- To: www-lib@w3.org
Hello, I have a peculiar problem, and I'm guessing that it's more of a newbie issue. I'm writing a C++ wrapper around the libwww library, and want to use it to send a whole bunch of requests, be it synchronous or asynchronous. I initialize a non-preemptive, caching client. Here's the problem. I send an asynchronous request, and get into the event loop. My call back function is called and everything looks fine, but control is never handed back to my main(), to fire off subsequent requests. Here're a few snippets of my code: main(): -- testHttpLib->sendGetRequest("http://www.google.com",xReqParams, 10000, (void *)testX->cbHandler, userParm); testHttpLib->sendGetRequest("http://www.google.com",xReqParams, 10000, (void *)testX->cbHandler, userParm); -- int Xhttp::sendGetRequest(const char * uri, XRequestParams * xreqParams, int timeout, void * cbFunc, void * userParam) { HTRequest * request = NULL; HTChunk * chunk = NULL; // Create a new request object request = HTRequest_new(); HTAlert_setInteractive(NO); // Set the trace and output methods in case application wants to log libwww msgs if ((slogFile) && (slogLevel) && (slogFileStream)) { HTSetTraceMessageMask(slogLevel); HTTrace_setCallback(sLogger); HTPrint_setCallback(sLogger); } // Add the call back function HTRequest_addAfter(request, (HTNetAfter *) cbFunc, NULL, userParam, HT_ALL, HT_FILTER_LAST, NO); (timeout == 0) ? HTHost_setEventTimeout(DefaultTimeout): HTHost_setEventTimeout(timeout); // Set the maximum number of retries HTRequest_setMaxRetry(xreqParams->getMaxRetries()); //HTRequest_setOutputFormat(request, HTAtom_for("text/xml")); // Check for the block and reload flags if (xreqParams->getBlock()) { HTRequest_setPreemptive(request, YES); } else { HTRequest_setPreemptive(request, NO); } if (xreqParams->getReload()) { HTRequest_setReloadMode(request, HT_CACHE_FLUSH); } else { HTRequest_setReloadMode(request, HT_CACHE_OK); } // Setting the output format. If the output doesnt show up // it may be worthwhile trying to change the format // because the library thinks it's getting one kind of output, but it may // be getting something else. That's why the post request's output format // is set as text/xml HTRequest_setOutputFormat(request, WWW_SOURCE); HTAnchor * anchor = HTAnchor_findAddress(uri); /* Using the following provided methods dont work well in a * preemptive mode because the context is set only after HTLoadAnchorToChunk * returns. And the call back function is called as part of HTLoad.... * That will mean that the chunk is null and we cannot get the response. */ //chunk = HTLoadAnchorToChunk(anchor, request); //HTRequest_setContext(request, chunk); // Associating the chunk with the request so that we can retrieve the chunk // when we are given the request. HTStream * target = HTStreamToChunk(request, &chunk, 0); HTRequest_setContext(request,chunk); HTRequest_setAnchor(request, anchor); HTRequest_setOutputStream(request, target); HTLoad(request, NO); if ((!xreqParams->getBlock()) && (!sEventLoopStarted)) { HTEventList_loop(request); sEventLoopStarted = true; } return HT_OK; } Thanks in advance for any help in shooting this down, -M
Received on Thursday, 22 July 2004 19:47:22 UTC