W3C home > Mailing lists > Public > www-lib@w3.org > October to December 1998

Reply timeout

From: Mikhail Grouchinski <mgrouch@usa.net>
Date: 17 Dec 1998 15:26:16 -0000
Message-ID: <19981217152616.31789.qmail@findmail.com>
To: www-lib@w3.org
Hi all,

I receive HTTP response with 30 sec time-out.
I print out response body within a callback
registered with HTNet_addAfter. Maybe this is
not the right callback for my case? 

Here is the source code.

Thank you for any help.

#include <stdio.h>

#include "WWWLib.h"
#include "WWWTrans.h"
#include "WWWInit.h"
#include "WWWApp.h"

#ifdef LIBWWW_SHARED
#include "HTextImp.h"
#endif

#define APP_NAME  "GW-test"
#define APP_VER   "1.0"

typedef struct _Context {
    HTRequest *		request;
    HTAnchor *	      anchor;
    HTChunk *           chunk;
} Context;

PRIVATE int       FD = STDIN_FILENO;
PRIVATE HTEvent * FdEvent = NULL;

/*	Create a Context Object
**	-----------------------
*/
PRIVATE Context * Context_new (HTRequest *request, HTAnchor *anchor, HTChunk *chunk)
{
    Context * me;
    if ((me = (Context  *) HT_CALLOC(1, sizeof (Context))) == NULL)
        HT_OUTOFMEM("Context_new");
    me->request = request;
    me->anchor = anchor;
    me->chunk = chunk;
    HTRequest_setContext(request, (void *) me); 
    return me;
}

/*	Delete a Context Object
**	-----------------------
*/
PRIVATE BOOL Context_delete (Context * old)
{
    HT_FREE(old);
    return YES;
}

/*	Initialize LibWWW
**	-----------------------
*/
PRIVATE void init_libwww(const char * AppName, const char * AppVersion)
{
    HTLib_setAppName(AppName);
    HTLib_setAppVersion(AppVersion);

    HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new);
    HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new, HTBufferWriter_new);
    HTProtocol_add("http", "buffered_tcp", HTTP_PORT,	NO,	HTLoadHTTP,	NULL);
     
    HTNetInit();
    HTEventInit();
    HTNet_setMaxSocket(6);  /* Max sockets open simultaneously */
    HTProxy_getEnvVar();    /* Get proxy environment variables */
    HTMIMEInit();           /* Register MIME header parsers */

    HTAlert_setInteractive(NO);
}

/*	Process messages
**	-----------------------
*/
PRIVATE int process(int fd, void* param, HTEventType type)
{
    char        c;
    HTRequest * request = NULL;
    HTAnchor *  anchor = NULL;
    HTChunk *   chunk = NULL;
    Context *   context = NULL;

    c = getchar();
    if (c == '\n')  return HT_OK;

    printf("%c process\n", c);

    if (c == '1')  {
       request = HTRequest_new();
       anchor = HTAnchor_findAddress("http://infoworxnt");

       HTRequest_setOutputFormat(request, WWW_SOURCE);
       chunk = HTLoadAnchorToChunk(anchor, request);

       if (chunk)  {
           context = Context_new(request, anchor, chunk);
       }  
    }

    return HT_OK;
}

/*	Terminate request callback
**	-----------------------
*/
PRIVATE int terminate_handler(HTRequest * request, 
  HTResponse * response, void * param, int status) 
{
   Context* context = NULL;

   printf("terminate_handler\n");
  
   context = HTRequest_context(request);
   if (context)  {
       if (context->chunk && HTChunk_data(context->chunk)) {
           fprintf(stdout, "%s", HTChunk_data(context->chunk));
           HTChunk_delete(context->chunk);
       }

       /* Request completed */
       Context_delete(context);
       HTRequest_delete(request);
   }
}

int main (int argc, char ** argv)
{
    int     to = -1;
    int     status = 1;
    char *  context = NULL;

    WWWTRACE = SHOW_ALL_TRACE;    
    init_libwww(APP_NAME, APP_VER);
/*
    HTProfile_newNoCacheClient(APP_NAME, APP_VER);
*/
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
    FdEvent = HTEvent_new(process, context, HT_PRIORITY_MAX, to);
    HTEventList_register(FD, HTEvent_READ, FdEvent);

    if (status) HTEventList_loop(NULL);
    return 0;
}
Received on Thursday, 17 December 1998 10:26:22 EST

This archive was generated by hypermail pre-2.1.9 : Wednesday, 3 September 2003 17:59:25 EDT