Timeout bug in HTEvtLoop

As in all cases, either I've goofed up the example or I've uncovered a
bug.

I put an event timeout using the HTHost_setEventTimeout( int ) function,
and I am able to catch the event in a cbf after the appropriate amount
of time.   The problem occurs after the cbf as I want to break the event
loop and return control to another part of my program.   The terminate
handler calls the appropriate functions (from what I've seen in the
examples) but the code in the EventLoop (HTEvtLoop.c) doesn't do any
checking of the main loop variable that I've turned off with a call to
HTEventList_stopLoop().  I just goes on to read from a socket that will
never return anything.  It doesn't seem to matter what I return from the
cbf...  All the example programs just do an exit().

I've included a copy of the hacked showtext.c.  I've wrapped the
functions into a simple C++ class.  I've been testing this against a
simple CGI shell that just spits out some text then sleeps for some
short amount of time (10 secs vs the 5 secs I set for the timeout
callback).

Any help or insight would be appreciated.
-Mike Flynn
flynn5@home.com
/*
**      @(#) $Id: showtext.c,v 1.2 1999/03/01 13:41:55 frystyk Exp $
**      
**      Other libwww samples can be found at "http://www.w3.org/Library/Examples"
**      
**      Copyright (cİ 1995-1998 World Wide Web Consortium, (Massachusetts
**      Institute of Technology, Institut National de Recherche en
**      Informatique et en Automatique, Keio University). All Rights
**      Reserved. This program is distributed under the W3C's Software
**      Intellectual Property License. This program is distributed in the hope
**      that it will be useful, but WITHOUT ANY WARRANTY; without even the
**      implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
**      PURPOSE. See W3C License http://www.w3.org/Consortium/Legal/ for more
**      details.
**
**      Parses a HTML document and prints out all the text ASIS stdout
*/

#include "WWWLib.h"
#include "WWWInit.h"
#include "WWWHTML.h"


class MyClient
{
public:
        MyClient() {};
        ~MyClient() { fprintf(stderr, "in the dtor\n"); }
        
        static int printer(const char * fmt, va_list pArgs);
        static int terminate_handler (HTRequest * request, HTResponse * response,
                                                        void * param, int status);
        static void parseText (HText * text, const char * buf, int len);
        int sendTasks(const char* url);

};

int MyClient::printer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stdout, fmt, pArgs));
}


int MyClient::terminate_handler (HTRequest * request, HTResponse * response,
                               void * param, int status) 
{
    if (status != HT_LOADED)
    {
        HTAlertCallback *cbf = HTAlert_find(HT_A_MESSAGE);
        fprintf(stderr, "MyClient:  In the error callback\n");
        if (cbf) (*cbf)(request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
                        HTRequest_error(request), NULL);
    }
    else
        fprintf(stderr, "MyClient:  In the error callback (LOADED)\n");


    /* We are done with this request */
    HTRequest_delete(request);

    /* Terminate libwww */
    HTProfile_delete();

    HTEventList_stopLoop();

    HTNet_killAll();

    // return HT_ERROR;   // What do I really return?
    return HT_OK; 
}

void MyClient::parseText (HText * text, const char * buf, int len)
{
    fprintf(stderr, "MyClient:  In the text callback\n");
    if (buf)
    {
        fwrite(buf, 1, len, stderr);
	if (strstr(buf, "PASS"))
        	fprintf(stderr, "MyClient:  PASS\n");
	else
        	fprintf(stderr, "MyClient:  FAIL\n");

    }
}

int MyClient::sendTasks(const char* url)
{
    char * uri = NULL;
    uri = HTParse(url, NULL, PARSE_ALL);

    /* Create a new premptive client */
    HTProfile_newHTMLNoCacheClient ("ShowTags", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(printer);

    /* Set trace messages and alert messages */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own termination filter */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /*
    ** Register our HTML element handler. We don't actually create a HText
    ** object as this is not needed. We only register the specific link
    ** callback.
    */
    HText_registerTextCallback(parseText);

    if (uri) {
        HTRequest * request = NULL;
        HTAnchor * anchor = NULL;
        BOOL status = NO;

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

        /* Setup a timeout on the request for 5 secs */
        HTHost_setEventTimeout(5000);

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

        /* Issue the GET and store the result in a chunk */
        status = HTLoadAnchor(anchor, request);

        /* Go into the event loop... */
        if (status == YES) HTEventList_loop(request);
    }

    return 0;
}

int main(int argc, char** argv)
{
    /* Handle command line args */
    if (argc != 2)
        {
        printf("Type the URI to print out a list of embedded links\n");
        printf("\t%s <uri>\n", argv[0]);
        printf("For example:\n");
        printf("\t%s http://www.w3.org\n", argv[0]);
    }
        
    MyClient foo;
    foo.sendTasks(argv[1]);

    return 0;
}

Received on Monday, 21 February 2000 10:02:07 UTC