--------------------- PatchSet 7065 Date: 2005/10/05 06:55:30 Author: adri Branch: tidyup_deferred_reads Tag: (none) Log: Start refactoring the IO part of httpReadReply() so its not to enormous. No functionality has been changed. Members: src/http.c:1.17.6.27.4.1->1.17.6.27.4.2 Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.17.6.27.4.1 retrieving revision 1.17.6.27.4.2 diff -u -r1.17.6.27.4.1 -r1.17.6.27.4.2 --- squid/src/http.c 27 Sep 2005 04:57:14 -0000 1.17.6.27.4.1 +++ squid/src/http.c 5 Oct 2005 06:55:30 -0000 1.17.6.27.4.2 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.17.6.27.4.1 2005/09/27 04:57:14 adri Exp $ + * $Id: http.c,v 1.17.6.27.4.2 2005/10/05 06:55:30 adri Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -550,38 +550,29 @@ return 1; } -/* This will be called when data is ready to be read from fd. Read until - * error or connection closed. */ -/* XXX this function is too long! */ -static void -httpReadReply(int fd, void *data) + +static int +httpReadReplyData(int fd, HttpStateData *httpState, char *buf, int *read_sz) { - 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 = SQUID_TCP_SO_RCVBUF; #if DELAY_POOLS delay_id delay_id; #endif - if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { - comm_close(fd); - return; - } #if DELAY_POOLS /* special "if" only for http (for nodelay proxy conns) */ if (delayIsNoDelay(fd)) delay_id = 0; else - delay_id = delayMostBytesAllowed(entry->mem_obj, &read_sz); + delay_id = delayMostBytesAllowed(entry->mem_obj, read_sz); #endif errno = 0; statCounter.syscalls.sock.reads++; - len = FD_READ_METHOD(fd, buf, read_sz); + 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); @@ -595,6 +586,32 @@ clen >>= 1; IOStats.Http.read_hist[bin]++; } + return len; +} + + +/* This will be called when data is ready to be read from fd. Read until + * error or connection closed. */ +/* XXX this function is too long! */ +static void +httpReadReply(int fd, 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 = SQUID_TCP_SO_RCVBUF; + + if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { + comm_close(fd); + return; + } + + len = httpReadReplyData(fd, httpState, buf, &read_sz); + if (!httpState->reply_hdr.size && len > 0 && fd_table[fd].uses > 1) { /* Skip whitespace */ while (len > 0 && xisspace(*buf)) @@ -606,6 +623,7 @@ return; } } + if (len < 0) { debug(50, 2) ("httpReadReply: FD %d: read failure: %s.\n", fd, xstrerror());