W3C home > Mailing lists > Public > www-lib@w3.org > July to September 2004

Newbie Question: Asynchronous Requests and EventLoop

From: Mahesh Shankar <mahesh@iptechniques.com>
Date: Thu, 22 Jul 2004 16:46:34 -0700
Message-ID: <410051DA.9010605@iptechniques.com>
To: www-lib@w3.org


I have a peculiar problem, and I'm guessing that it's more of a newbie 

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:

  testHttpLib->sendGetRequest("http://www.google.com",xReqParams, 10000, 
(void *)testX->cbHandler,
  testHttpLib->sendGetRequest("http://www.google.com",xReqParams, 10000, 
(void *)testX->cbHandler,
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();

  // Set the trace and output methods in case application wants to log 
libwww msgs

  if ((slogFile) && (slogLevel) && (slogFileStream))
  // Add the call back function
  HTRequest_addAfter(request, (HTNetAfter *) cbFunc, NULL, userParam, 
             HT_FILTER_LAST, NO);
  (timeout == 0) ? HTHost_setEventTimeout(DefaultTimeout): 
  // Set the maximum number of retries

  //HTRequest_setOutputFormat(request, HTAtom_for("text/xml")); 

  // Check for the block and reload flags
  if (xreqParams->getBlock())
    HTRequest_setPreemptive(request, YES);
    HTRequest_setPreemptive(request, NO);
  if (xreqParams->getReload())
    HTRequest_setReloadMode(request, HT_CACHE_FLUSH);
    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 
   * 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 
  // when we are given the request.
  HTStream * target = HTStreamToChunk(request, &chunk, 0);
  HTRequest_setAnchor(request, anchor);
  HTRequest_setOutputStream(request, target);
  HTLoad(request, NO);

  if ((!xreqParams->getBlock()) && (!sEventLoopStarted))
    sEventLoopStarted = true;
  return HT_OK;

Thanks in advance for any help in shooting this down,

Received on Thursday, 22 July 2004 19:47:22 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:56 UTC