Http GET request hangs at HostEvent function at HTHost.c

Hi,

It will be appreciated if any of libwww experts can help me out.  It is 
just a normal http HEAD request, but it hangs.  It is not repeatable.  If I 
restart my process, it will not happen.

It basically stuck in this loop at HTHost.c

PRIVATE int HostEvent (SOCKET soc, void * pVoid, HTEventType type)
{
     HTHost * host = (HTHost *)pVoid;

     if (type == HTEvent_READ || type == HTEvent_CLOSE || type == 
HTEvent_ACCEPT) {
         HTNet * targetNet;

         /* call the first net object */
         do {
             int ret;

             /* netscape and apache servers can do a lazy close well after 
usage
              * of previous socket has been dispensed by the library,
              * the section below makes sure the event does not get miss 
attributed
              */
             if (HTChannel_socket(host->channel) != soc && type != 
HTEvent_ACCEPT && !host->listening) {
                 HTTRACE(CORE_TRACE, "Host Event.. wild socket %d type = %s 
real socket is %d\n" _ soc _
                         type == HTEvent_CLOSE ? "Event_Close" : "Event_Read" _
                         HTChannel_socket(host->channel));
                 return HT_OK;
             }

             targetNet = (HTNet *)HTList_firstObject(host->pipeline);
             if (targetNet) {
                 HTTRACE(CORE_TRACE, "Host Event.. READ passed to `%s\'\n" _
                             HTAnchor_physical(HTRequest_anchor(HTNet_request(targetNet))));
                 if ((ret = 
(*targetNet->event.cbf)(HTChannel_socket(host->channel),
                                                   targetNet->event.param, 
type)) != HT_OK)
                     return ret;
             }
             if (targetNet == NULL && host->remainingRead > 0) {
                 HTTRACE(CORE_TRACE, "HostEvent... Error: %d bytes left to 
read and nowhere to put them\n" _
                             host->remainingRead);
                 host->remainingRead = 0;
                 /*
                 **      Fall through to close the channel
                 */
             }
         /* call pipelined net object to eat all the data in the channel */
         } while (host->remainingRead > 0);


Here host->remainingRead is 159, type is HTEvent_READ

Here is the calling stack:  this function will

     call --> (targetNet->event.cbf)
	call --> HTTPEvent() at HTTP.c
	      .... eventually
		call ---> HTReader_read,
			        ---> call socket read
			        <---- return EAGAIN
		<---- return WOULDBLOCK.
	<---- return H_OK at HTTP.c


The questions are:

1) Why there is 159 byte remainingRead in HTHost, but there is not data in 
the socket read buffer?  How and when did remainingRead get set?

2)  Why HTTPEvent function needs to convert HT_WOULD_BLOCK into HT_OK.

    1309               } else if (type == HTEvent_READ) {
    1310                   status = HTHost_read(host, net);
    1311                   if (status == HT_WOULD_BLOCK)
    1312                       return HT_OK;

If it returns HT_WOULD_BLOCK here, we will come out of the loop,  so 
eventually we will time-out by READ event.  It will be better than this 
infinite loop.

3) Could it be caused by my modification on HTReader_read which we added 
some bandwidth control code here, if we could not get bandwidth, we return 
HT_WOULD_BLOCK.

     do {
         /* don't read if we have to push unwritten data from last call */
         if (me->write >= me->read) {
====>  this is the part we added
                if (  !GetBandwidth() ) {
                     HTHost_register(host, net, HTEvent_READ);
                     return HT_WOULD_BLOCK;
	       }
===>
                 if ((me->b_read = NETREAD(soc, me->data, token_size)) < 0) {



Thanks,

-Wayne

Received on Wednesday, 11 December 2002 23:05:24 UTC