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

how to return from callback function back to main( )?

From: Jerry G. Chiuan <jerry@oridus.com>
Date: Thu, 28 Aug 2003 21:35:41 -0700
Message-ID: <0c9c01c36de7$01d93170$25a8a8a8@piglet>
To: <www-lib@w3.org>

Hi All,
I am trying to use the same mechanism shown in this example to POST data to
the HTTP server and  save the result in a chunk


As I know, the program goes into the event loop to wait for the response
after calling HTPostFormAnchorToChunk( )
then, terminate_handler would be invoked once the response is received (or
timeout occurs)

However, I would like to handle the response in terminate_handler, return
from terminate_handler to back main( ), then keep doing something else
after this line HTEventList_loop(request).
Or, I just simply want to wait for the response in the event loop, then do
something to handle response afterwards ( don't invoke terminate_handler )

is it possible? if yes, how shall I do?

ps: please refer to the sample code below

- Jerry

PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
			       void * param, int status)
    if (status == HT_LOADED && result && HTChunk_data(result)) {
	HTPrint("%s", HTChunk_data(result));

    /* We are done with this request */

    /* Terminate libwww */


int main (int argc, char ** argv)

    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Set the timeout for long we are going to wait for a response */


    /* Create a request */
    request = HTRequest_new();

	    /* Set the default output to "asis" */
    HTRequest_setOutputFormat(request, WWW_SOURCE);

    /* Get an anchor object for the URI */
   anchor = HTAnchor_findAddress(uri);

    /* Post the data and get the result in a chunk */
    result = HTPostFormAnchorToChunk(formfields, anchor, request);

    /* Clean up the form fields */

   /* Go into the event loop... */

   return 0;
Received on Friday, 29 August 2003 00:33:20 UTC

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