Re: HTEndLoop flag not reset.

Henrik Frystyk Nielsen wrote:
> 
> Michael Saunders wrote:
> 
> > There are several places within the HTEventList_loop function that perform a
> > return without resetting the HTEndLoop flag back to zero. I believe that in the
> > last revision you added the instruction at the end of the function that reset it
> > to zero but this is not the only exit point from this function. It appears there
> > are six other "return" statements within the HTEventList_loop function that need
> > should be changed from:
> 
> Hi Michael,
> 
> The only return statements that I can see are within the loop where we
> have already checked that HTEndLoop is 0 so it shouldn't be necessary to
> reset it again, no?
> 

Henrik,

I have included snippets of the HTEventList_loop below that highlight the
sections of code that do not reset the HTEndLoop variable before returning.
You will note that the very last return in the function HTEndLoop is reset
to zero and the comment says it is done just in case we want to start the
loop again. As it stands, this event loop can only be restarted if we exit
from the last return. If we exit from any of the other return statements
then the HTEndLoop flag might be set to 1 (because HTEventList_stopLoop
may have been called).

To be honest, I am not entirely certain why the HTEndLoop variable is not
set to zero before entering the loop and the "while(!HTEndLoop) { ... }"
is not changed to a "do { ... } while (!HTEndLoop);". Am I missing the
point here?

Thanks,
Michael

HTEvtLst.c code snippet:
------------------------

PUBLIC int HTEventList_loop (HTRequest * theRequest)
{
...

    /* Don't leave this loop until we leave the application */
    while (!HTEndLoop) {

        /*
	**  Timeval struct copy needed for linux, as it set the value to the
	**  remaining timeout while exiting the select. (and perhaps for
	**  other OS). Code borrowed from X server.
	*/
	wt = NULL;
	if ((status = HTTimer_next(&timeout)))
	    return status;

*********** ^^^^^^^^^^^^^^ *************************************
...


        if (active_sockets == -1) {
...
	    HTTRACE(THD_TRACE, "Event Loop.. select returned error %d\n" _ socerrno);

#ifdef HTDEBUG
	    EventList_dump();
#endif /* HTDEBUG */

	    return HT_ERROR;

*********** ^^^^^^^^^^^^^^ *************************************

        }

	/*
	**  We had a timeout so now we check and see if we have a timeout
	**  handler to call. Let HTTimer_next get it.
	*/ 
	if (active_sockets == 0)
	    continue;

	/* There were active sockets. Determine which fd sets they were in */
	for (s = 0 ; s <= maxfds ; s++) { 
	    if (FD_ISSET(s, &texceptset))
		if ((status = EventOrder_add(s, HTEvent_OOB, now)) != HT_OK)
		    return status;
******************* ^^^^^^^^^^^^^^ *************************************
	    if (FD_ISSET(s, &twriteset))
		if ((status = EventOrder_add(s, HTEvent_WRITE, now)) != HT_OK)
		    return status;
******************* ^^^^^^^^^^^^^^ *************************************
	    if (FD_ISSET(s, &treadset))
		if ((status = EventOrder_add(s, HTEvent_READ, now)) != HT_OK)
		    return status;
******************* ^^^^^^^^^^^^^^ *************************************
	}
	if ((status = EventOrder_executeAndDelete()) != HT_OK) return status;
************************************************************** ^^^^^^^^^^^^^^
    };

    /* Reset HTEndLoop in case we want to start again */
    HTEndLoop = 0;
*** ^^^^^^^^^^^^^^ *** this is the only place that you reset before returning
    return HT_OK;
#endif /* !WWW_WIN_ASYNC */
}

Received on Tuesday, 22 June 1999 19:45:11 UTC