--------------------- PatchSet 5227 Date: 2002/10/05 06:30:22 Author: adri Branch: commloops Tag: (none) Log: Convert http.c over to use comm_read(). I'm partially breaking delay pools on the initial read - I'll fix this later. Members: src/http.c:1.20.8.4->1.20.8.5 Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.20.8.4 retrieving revision 1.20.8.5 diff -u -r1.20.8.4 -r1.20.8.5 --- squid/src/http.c 4 Oct 2002 13:36:31 -0000 1.20.8.4 +++ squid/src/http.c 5 Oct 2002 06:30:22 -0000 1.20.8.5 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.20.8.4 2002/10/04 13:36:31 rbcollins Exp $ + * $Id: http.c,v 1.20.8.5 2002/10/05 06:30:22 adri Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -47,7 +47,7 @@ static CWCB httpSendComplete; static CWCB httpSendRequestEntity; -static PF httpReadReply; +static IOCB httpReadReply; static void httpSendRequest(HttpStateData *); static PF httpStateFree; static PF httpTimeout; @@ -538,16 +538,15 @@ * error or connection closed. */ /* XXX this function is too long! */ static void -httpReadReply(int fd, void *data) +httpReadReply(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data) { HttpStateData *httpState = data; - LOCAL_ARRAY(char, buf, SQUID_TCP_SO_RCVBUF); StoreEntry *entry = httpState->entry; const request_t *request = httpState->request; - int len; int bin; int clen; - size_t read_sz; + size_t read_sz = SQUID_TCP_SO_RCVBUF; + int do_next_read = 0; #if DELAY_POOLS delay_id delay_id; @@ -557,21 +556,23 @@ else delay_id = delayMostBytesAllowed(entry->mem_obj); #endif + + assert(buf == httpState->buf); + if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { comm_close(fd); - return; + do_next_read = 0; + goto finish; } - /* check if we want to defer reading */ + errno = 0; - read_sz = SQUID_TCP_SO_RCVBUF; + /* prepare the read size for the next read (if any) */ #if DELAY_POOLS read_sz = delayBytesWanted(delay_id, 1, read_sz); #endif - statCounter.syscalls.sock.reads++; - len = FD_READ_METHOD(fd, buf, read_sz); - debug(11, 5) ("httpReadReply: FD %d: len %d.\n", fd, len); - if (len > 0) { - fd_bytes(fd, len, FD_READ); + + debug(11, 5) ("httpReadReply: FD %d: len %d.\n", fd, (int)len); + if (flag == COMM_OK && len > 0) { #if DELAY_POOLS delayBytesIn(delay_id, len); #endif @@ -583,40 +584,43 @@ clen >>= 1; IOStats.Http.read_hist[bin]++; } - if (!httpState->reply_hdr && len > 0) { + if (!httpState->reply_hdr && flag == COMM_OK && len > 0) { /* Skip whitespace */ while (len > 0 && xisspace(*buf)) xmemmove(buf, buf + 1, len--); if (len == 0) { /* Continue to read... */ - commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0); - return; + do_next_read = 1; + goto finish; } } - if (len < 0) { + if (flag != COMM_OK || len < 0) { debug(50, 2) ("httpReadReply: FD %d: read failure: %s.\n", fd, xstrerror()); if (ignoreErrno(errno)) { - commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0); + do_next_read = 1; } else if (entry->mem_obj->inmem_hi == 0) { ErrorState *err; err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR); err->request = requestLink((request_t *) request); err->xerrno = errno; fwdFail(httpState->fwd, err); + do_next_read = 0; comm_close(fd); } else { + do_next_read = 0; comm_close(fd); } - } else if (len == 0 && entry->mem_obj->inmem_hi == 0) { + } else if (flag == COMM_OK && len == 0 && entry->mem_obj->inmem_hi == 0) { ErrorState *err; err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE); err->xerrno = errno; err->request = requestLink((request_t *) request); fwdFail(httpState->fwd, err); httpState->eof = 1; + do_next_read = 0; comm_close(fd); - } else if (len == 0) { + } else if (flag == COMM_OK && len == 0) { /* Connection closed; retrieval done. */ httpState->eof = 1; if (httpState->reply_hdr_state < 2) @@ -628,6 +632,7 @@ */ httpProcessReplyHeader(httpState, buf, len); fwdComplete(httpState->fwd); + do_next_read = 0; comm_close(fd); } else { if (httpState->reply_hdr_state < 2) { @@ -657,7 +662,7 @@ /* yes we have to clear all these! */ commSetDefer(fd, NULL, NULL); commSetTimeout(fd, -1, NULL, NULL); - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + do_next_read = 0; #if DELAY_POOLS delayClearNoDelay(fd); #endif @@ -669,9 +674,13 @@ httpStateFree(fd, httpState); } else { /* Wait for EOF condition */ - commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0); + do_next_read = 1; } } + +finish: + if (do_next_read) + comm_read(fd, httpState->buf, read_sz, httpReadReply, httpState); } /* This will be called when request write is complete. Schedule read of @@ -692,18 +701,20 @@ kb_incr(&statCounter.server.all.kbytes_out, size); kb_incr(&statCounter.server.http.kbytes_out, size); } - if (errflag == COMM_ERR_CLOSING) - return; + if (errflag == COMM_ERR_CLOSING) { + return; + } if (errflag) { err = errorCon(ERR_WRITE_ERROR, HTTP_INTERNAL_SERVER_ERROR); err->xerrno = errno; err->request = requestLink(httpState->orig_request); errorAppendEntry(entry, err); comm_close(fd); - return; + return; } else { /* Schedule read reply. */ - commSetSelect(fd, COMM_SELECT_READ, httpReadReply, httpState, 0); + /* XXX we're not taking into account delay pools on this read! */ + comm_read(fd, httpState->buf, SQUID_TCP_SO_RCVBUF, httpReadReply, httpState); /* * Set the read timeout here because it hasn't been set yet. * We only set the read timeout after the request has been