--------------------- PatchSet 10344 Date: 2007/12/29 10:57:49 Author: adri Branch: s27_adri Tag: (none) Log: Convert http.c to use a buf_t for its incoming buffer rather than the MemBuf. The reply header membuf (httpState->reply_hdr) was hanging around in memory until the reply was complete; it was used in a couple of places to check whether the response header needed "checking" (for zero-sized replies and for trimming whitespace.) It now uses the http parser "state" (if you can call it that..) to determine whether the current buffer is being parsed for headers. Members: src/http.c:1.63.2.3.4.26->1.63.2.3.4.27 src/structs.h:1.158.2.5.4.10->1.158.2.5.4.11 Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.63.2.3.4.26 retrieving revision 1.63.2.3.4.27 diff -u -r1.63.2.3.4.26 -r1.63.2.3.4.27 --- squid/src/http.c 29 Dec 2007 09:08:23 -0000 1.63.2.3.4.26 +++ squid/src/http.c 29 Dec 2007 10:57:49 -0000 1.63.2.3.4.27 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.63.2.3.4.26 2007/12/29 09:08:23 adri Exp $ + * $Id: http.c,v 1.63.2.3.4.27 2007/12/29 10:57:49 adri Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -73,9 +73,8 @@ } } storeUnlockObject(httpState->entry); - if (!memBufIsNull(&httpState->reply_hdr)) { - memBufClean(&httpState->reply_hdr); - } + if (httpState->replybuf) + httpState->replybuf = buf_deref(httpState->replybuf); requestUnlink(httpState->request); requestUnlink(httpState->orig_request); httpState->request = NULL; @@ -440,6 +439,8 @@ debug(11, 3) ("httpProcessReplyHeader: key '%s'\n", storeKeyText(entry->hash.key)); + debug(11, 2) ("httpProcessReplyHeaderBlock: FD %d: given %d byets to look at\n", httpState->fd, size); + assert(httpState->reply_hdr_state == 0); hdr_len = size; @@ -669,6 +670,7 @@ ssize_t len = slen - offset; assert(len >= 0); storeBuffer(entry); + debug(11, 2) ("httpAppendBody: FD %d: given %d bytes to look at\n", httpState->fd, (int) len); while (len > 0) { if (httpState->chunk_size > 0) { size_t size = len; @@ -676,11 +678,13 @@ size = httpState->chunk_size; httpState->chunk_size -= size; storeAppend(httpState->entry, buf, size); + debug(11, 2) ("httpAppendBody: FD %d: appended %d bytes\n", httpState->fd, (int) size); buf += size; len -= size; } else if (httpState->chunk_size < 0) { /* non-chunked without content-length */ storeAppend(httpState->entry, buf, len); + debug(11, 2) ("httpAppendBody: FD %d: appended %d bytes\n", httpState->fd, (int) len); len = 0; } else if (httpState->flags.chunked) { char *eol = memchr(buf, '\n', len); @@ -772,7 +776,7 @@ } /* Is it a incomplete reply? */ if (httpState->chunk_size > 0) { - debug(11, 1) ("Short response from '%s' on port %d. Expecting %" PRINTF_OFF_T " octets more\n", storeUrl(entry), comm_local_port(fd), httpState->chunk_size); + debug(11, 1) ("Short response from FD %d: '%s' on port %d. Expecting %" PRINTF_OFF_T " octets more\n", fd, storeUrl(entry), comm_local_port(fd), httpState->chunk_size); comm_close(fd); return; } @@ -873,6 +877,7 @@ int clen; int done = 0; size_t read_sz = SQUID_TCP_SO_RCVBUF; + int oldlen = -1; #if DELAY_POOLS delay_id delay_id; #endif @@ -896,9 +901,11 @@ statCounter.syscalls.sock.reads++; /* XXX this breaks delay pools for now - need to pass in a 'max read size' parameter to memBufFill */ - if (memBufIsNull(&httpState->reply_hdr)) - memBufDefInit(&httpState->reply_hdr); - len = memBufFill(&httpState->reply_hdr, fd); + if (httpState->replybuf == NULL) + httpState->replybuf = buf_create_size(8192); + oldlen = buf_len(httpState->replybuf); + len = buf_fill(httpState->replybuf, fd, 1); + debug(11, 2) ("httpReadReply: FD %d: read %d bytes, buffer changed from %d to %d bytes\n", fd, (int) len, (int) oldlen, buf_len(httpState->replybuf)); buffer_filled = len == read_sz; debug(11, 5) ("httpReadReply: FD %d: len %d.\n", fd, (int) len); @@ -914,10 +921,10 @@ clen >>= 1; IOStats.Http.read_hist[bin]++; } - if (!httpState->reply_hdr.size && len > 0 && fd_table[fd].uses > 1) { + if (httpState->reply_hdr_state == 0 && oldlen == 0 && len > 0 && fd_table[fd].uses > 1) { /* Skip whitespace */ /* XXX must redo this later once we're using buf's and offset pointers, not MemBuf's */ - while (len > 0 && xisspace(*(httpState->reply_hdr.buf + buf_start))) { + while (len > 0 && xisspace(buf_get_chr(httpState->replybuf, buf_start))) { buf_start++; len--; } @@ -928,6 +935,7 @@ return; } } + debug(11, 2) ("httpReadReply: FD %d: buf_start is %d, leaving %d bytes in the buffer\n", httpState->fd, buf_start, buf_len(httpState->replybuf) - buf_start); if (len < 0) { debug(11, 2) ("httpReadReply: FD %d: read failure: %s.\n", fd, xstrerror()); @@ -940,7 +948,7 @@ fwdFail(httpState->fwd, err); comm_close(fd); } - } else if (len == 0 && entry->mem_obj->inmem_hi == 0 && !httpState->reply_hdr.size) { + } else if (httpState->reply_hdr_state == 0 && len == 0 && entry->mem_obj->inmem_hi == 0 && oldlen == 0) { fwdFail(httpState->fwd, errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_BAD_GATEWAY, httpState->fwd->request)); httpState->eof = 1; comm_close(fd); @@ -955,9 +963,9 @@ * we want to process the reply headers. */ /* Fake an "end-of-headers" to work around such broken servers */ - memBufAppend(&httpState->reply_hdr, "\r\n", 2); - assert(buf_start < httpState->reply_hdr.size); - httpProcessReplyHeaderBlock(httpState, httpState->reply_hdr.buf, httpState->reply_hdr.size, buf_start); + buf_append(httpState->replybuf, "\r\n", 2, BF_NONE); + assert(buf_start < buf_len(httpState->replybuf)); + httpProcessReplyHeaderBlock(httpState, buf_buf(httpState->replybuf), buf_len(httpState->replybuf), buf_start); } if (entry->mem_obj->reply->sline.status == HTTP_HEADER_TOO_LARGE) { storeEntryReset(entry); @@ -980,8 +988,9 @@ * httpAppendBody(). */ storeBuffer(entry); - assert(buf_start < httpState->reply_hdr.size); - done = httpProcessReplyHeaderBlock(httpState, httpState->reply_hdr.buf, httpState->reply_hdr.size, buf_start); + assert(buf_start < buf_len(httpState->replybuf)); + done = httpProcessReplyHeaderBlock(httpState, buf_buf(httpState->replybuf), buf_len(httpState->replybuf), buf_start); + debug(11, 2) ("httpReadReply: FD %d: httpProcessReplyHeaderBlock consumed %d bytes\n", httpState->fd, done); if (httpState->reply_hdr_state == 2) { http_status s = entry->mem_obj->reply->sline.status; if (s == HTTP_HEADER_TOO_LARGE) { @@ -1007,8 +1016,8 @@ httpHeaderPutTime(&reply->header, HDR_DATE, squid_curtime); mb = httpReplyPack(reply); storeAppend(entry, mb.buf, mb.size); - assert(buf_start < httpState->reply_hdr.size); - storeAppend(entry, httpState->reply_hdr.buf + buf_start, httpState->reply_hdr.size - buf_start); + assert(buf_start < buf_len(httpState->replybuf)); + storeAppend(entry, buf_buf(httpState->replybuf) + buf_start, buf_len(httpState->replybuf) - buf_start); httpReplyReset(reply); httpReplyParse(reply, mb.buf, mb.size); memBufClean(&mb); @@ -1028,12 +1037,12 @@ return; } } - assert(! memBufIsNull(&httpState->reply_hdr)); - assert(buf_start - done < httpState->reply_hdr.size); + assert(httpState->replybuf); + assert(buf_start - done < buf_len(httpState->replybuf)); cbdataLock(httpState); - httpAppendBody(httpState, httpState->reply_hdr.buf, httpState->reply_hdr.size, done + buf_start, buffer_filled); - if (cbdataValid(httpState) && (! memBufIsNull(&httpState->reply_hdr))) - memBufReset(&httpState->reply_hdr); + httpAppendBody(httpState, buf_buf(httpState->replybuf), buf_len(httpState->replybuf), done + buf_start, buffer_filled); + if (cbdataValid(httpState) && httpState->replybuf) + httpState->replybuf = buf_deref(httpState->replybuf); cbdataUnlock(httpState); return; } Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.158.2.5.4.10 retrieving revision 1.158.2.5.4.11 diff -u -r1.158.2.5.4.10 -r1.158.2.5.4.11 --- squid/src/structs.h 29 Dec 2007 07:21:43 -0000 1.158.2.5.4.10 +++ squid/src/structs.h 29 Dec 2007 10:57:49 -0000 1.158.2.5.4.11 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.158.2.5.4.10 2007/12/29 07:21:43 adri Exp $ + * $Id: structs.h,v 1.158.2.5.4.11 2007/12/29 10:57:49 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1108,7 +1108,6 @@ buf_t *replybuf; StoreEntry *entry; request_t *request; - MemBuf reply_hdr; int reply_hdr_state; peer *peer; /* peer request made to */ int eof; /* reached end-of-object? */