W3C home > Mailing lists > Public > www-lib@w3.org > April to June 1999

Starting requests in event loops, was Re: The tiny web browser

From: Neil Stewart <nstewart@cadence.com>
Date: Thu, 27 May 1999 17:50:05 +0100
Message-ID: <374D77BD.7AA2F270@cadence.com>
To: libwww Mailing List <www-lib@w3.org>
Henrik Frystyk Nielsen wrote:
> 
> I am not sure - I have the same problem on NT where a console app like
> the tiny browser for some reason can't register stdin even though it is
> in fact defined as a socket.
> 
> Despite doing something like polling I am not sure what to do except
> rolling your own. if you want to do polling then you can register an
> event handler with a timeout of, say 100 ms - just to see if that works.
> 
> Henrik

OK, I've decided that polling is acceptable, as it's checking for user
input which doesn't happen very quickly. However, I now need to
initiate HTTP requests in the middle of my timer callback function.
The calback itself works, but I can't see how to initiate a request
without actually actioning the request.

Previously, I had a main function that did this:

    initialiseLibwww();
    while(1)
    {
        waitForURL();
        HTChunk* chunk = HTLoadToChunk(url, request);
        char* buf = HTChunk_data(chunk);
        returnBuffer(buf);
    }

ie. wait for a request, action it, and return the buffer pointer. This
works fine, though I can't get user input while downloading files. So
I moved on to a main function that does this:

    initialiseLibwww();
    HTTimer* myTimer = HTTimer_new(NULL, timerCallback, ...);
    HTEventList_newLoop();
    /*+++ theoretically never returns! */

and had a separate callback function like this:

    checkForURL();
    if(no URL) return;
    ???? [download URL to local buffer]

So my problem is, what to do at ???? to initiate a request? I don't
think I can do a HTLoadToChunk, as it wont return until the request
has been actioned. And anyway, I don't think libwww is very happy
about being re-entered!

Has anyone else done anything like this? Or can you point me in the
direction of an example application that does this (I couldn't find
anything relevant when I looked, but I may have missed something).

Thanks,

Neil

-- 
Neil Stewart                |      Cadence Design Systems Ltd
Consulting Engineer         |                   1 Bell Square
email: nstewart@cadence.com |      Brucefield Industrial Park
phone/vmail: 01506 595072   | Livingston, SCOTLAND,  EH54 9BY
Received on Thursday, 27 May 1999 12:50:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:29 GMT