From: wessels <> Date: Thu, 23 Oct 1997 11:13:36 +0000 (+0000) Subject: Ripped out old 'comm_set_stall()' stuff. This broke because we would X-Git-Tag: SQUID_3_0_PRE1~4730 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da2b3a175543fa5e9a0aef933e7b3d3042b96edc;p=thirdparty%2Fsquid.git Ripped out old 'comm_set_stall()' stuff. This broke because we would decide to delay the server side for some fixed amount of time (1s), but if the condition changed before that time was up, there was no way to 'undo' the stall. Now we have a 'check_defer' function associated with a FD. We'll call F->check_defer every time through select(). --- diff --git a/src/cf.data.pre b/src/cf.data.pre index 09c8db9b02..8c1b6f7f34 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1034,24 +1034,6 @@ read_timeout 15 minutes DOC_END -NAME: defer_timeout -COMMENT: (in minutes) -TYPE: time_t -LOC: Config.Timeout.defer -DEFAULT: 1 hour -DOC_START - If your clients are behind slow (e.g. PPP/SLIP) connections, - then data may come in from the server-side faster than it can - be written to the client-side. When the server side gets too - far ahead of the client-side, subsequent reads will be deferred - until the client catches up. This timeout determines how long - to wait while in "deferred read mode." The default is one - hour. - -defer_timeout 1 hour -DOC_END - - NAME: request_timeout TYPE: time_t LOC: Config.Timeout.request diff --git a/src/client.cc b/src/client.cc index 06a68203a8..96c0cc6e07 100644 --- a/src/client.cc +++ b/src/client.cc @@ -2,8 +2,9 @@ + /* - * $Id: client.cc,v 1.32 1997/10/20 22:59:43 wessels Exp $ + * $Id: client.cc,v 1.33 1997/10/23 05:13:37 wessels Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived diff --git a/src/comm.cc b/src/comm.cc index a9a9f29605..89dee33d3c 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,5 +1,6 @@ + /* - * $Id: comm.cc,v 1.189 1997/10/23 04:01:23 wessels Exp $ + * $Id: comm.cc,v 1.190 1997/10/23 05:13:37 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -154,6 +155,7 @@ static PF commHandleWrite; static int fdIsHttpOrIcp _PARAMS((int fd)); static IPH commConnectDnsHandle; static void commConnectCallback _PARAMS((ConnectStateData * cs, int status)); +static int commDeferRead(int fd); static struct timeval zero_tv; @@ -628,13 +630,20 @@ comm_udp_sendto(int fd, } void -comm_set_stall(int fd, int delta) +commSetDefer(int fd, DEFER * func) { - if (fd < 0) - return; - fd_table[fd].stall_until = squid_curtime + delta; + fde *F = &fd_table[fd]; + F->defer_check = func; } +static int +commDeferRead(int fd) +{ + fde *F = &fd_table[fd]; + if (F->defer_check == NULL) + return 0; + return F->defer_check(fd, F->read_data); +} #if HAVE_POLL @@ -661,7 +670,7 @@ comm_poll_incoming(void) for (j = 0; j < NHttpSockets; j++) { if (HttpSockets[j] < 0) continue; - if (fd_table[HttpSockets[j]].stall_until > squid_curtime) + if (commDeferRead(HttpSockets[j])) continue; fds[N++] = HttpSockets[j]; } @@ -724,7 +733,7 @@ comm_select_incoming(void) for (i = 0; i < NHttpSockets; i++) { if (HttpSockets[i] < 0) continue; - if (fd_table[HttpSockets[i]].stall_until > squid_curtime) + if (commDeferRead(HttpSockets[i])) continue; fds[N++] = HttpSockets[i]; } @@ -826,7 +835,7 @@ comm_poll(time_t sec) int events; events = 0; /* Check each open socket for a handler. */ - if (fd_table[i].read_handler && fd_table[i].stall_until <= squid_curtime) + if (fd_table[i].read_handler && !commDeferRead(i)) events |= POLLRDNORM; if (fd_table[i].write_handler) events |= POLLWRNORM; @@ -971,9 +980,7 @@ comm_select(time_t sec) maxfd = Biggest_FD + 1; for (i = 0; i < maxfd; i++) { /* Check each open socket for a handler. */ - if (fd_table[i].stall_until > squid_curtime) - continue; - if (fd_table[i].read_handler) { + if (fd_table[i].read_handler && !commDeferRead(i)) { nfds++; FD_SET(i, &readfds); } diff --git a/src/defines.h b/src/defines.h index 3b321f6bd4..da3981c9f7 100644 --- a/src/defines.h +++ b/src/defines.h @@ -175,7 +175,7 @@ */ #define ENTRY_VALIDATED (1<<16) -#define READ_DEFERRED (1<<15) +#define ENTRY_UNUSED15 (1<<15) #define ENTRY_NEGCACHED (1<<14) #define HIERARCHICAL (1<<13) /* can we query neighbors? */ #define KEY_PRIVATE (1<<12) /* is the key currently private? */ diff --git a/src/ftp.cc b/src/ftp.cc index cd20586a81..b7bd2900d9 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.144 1997/10/22 18:51:15 wessels Exp $ + * $Id: ftp.cc,v 1.145 1997/10/23 05:13:39 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -623,21 +623,6 @@ ftpReadData(int fd, void *data) /* check if we want to defer reading */ clen = entry->mem_obj->inmem_hi; off = storeLowestMemReaderOffset(entry); - if ((clen - off) > READ_AHEAD_GAP) { - IOStats.Ftp.reads_deferred++; - debug(9, 3) ("ftpReadData: Read deferred for Object: %s\n", - entry->url); - commSetSelect(fd, COMM_SELECT_READ, ftpReadData, data, 0); - if (!BIT_TEST(entry->flag, READ_DEFERRED)) { - commSetTimeout(fd, Config.Timeout.defer, NULL, NULL); - BIT_SET(entry->flag, READ_DEFERRED); - } - /* dont try reading again for a while */ - comm_set_stall(fd, 1); - return; - } else { - BIT_RESET(entry->flag, READ_DEFERRED); - } if (EBIT_TEST(ftpState->flags, FTP_ISDIR)) if (!EBIT_TEST(ftpState->flags, FTP_HTML_HEADER_SENT)) ftpListingStart(ftpState); @@ -1446,6 +1431,7 @@ ftpReadList(FtpStateData * ftpState) ftpReadData, ftpState, 0); + commSetDefer(ftpState->data.fd, protoCheckDeferRead); ftpState->state = READING_DATA; return; } else if (!EBIT_TEST(ftpState->flags, FTP_TRIED_NLST)) { @@ -1472,6 +1458,7 @@ ftpReadRetr(FtpStateData * ftpState) ftpReadData, ftpState, 0); + commSetDefer(ftpState->data.fd, protoCheckDeferRead); ftpState->state = READING_DATA; } else { ftpFail(ftpState); diff --git a/src/gopher.cc b/src/gopher.cc index 5a54882ad9..cc73d3cfba 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,6 +1,6 @@ /* - * $Id: gopher.cc,v 1.100 1997/10/22 05:50:29 wessels Exp $ + * $Id: gopher.cc,v 1.101 1997/10/23 05:13:39 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -684,28 +684,6 @@ gopherReadReply(int fd, void *data) /* check if we want to defer reading */ clen = entry->mem_obj->inmem_hi; off = storeLowestMemReaderOffset(entry); - if ((clen - off) > READ_AHEAD_GAP) { - IOStats.Gopher.reads_deferred++; - debug(10, 3) ("gopherReadReply: Read deferred for Object: %s\n", - entry->url); - debug(10, 3) (" Current Gap: %d bytes\n", clen - off); - /* reschedule, so it will automatically reactivated when - * Gap is big enough. */ - commSetSelect(fd, - COMM_SELECT_READ, - gopherReadReply, - data, 0); - /* don't install read timeout until we are below the GAP */ - if (!BIT_TEST(entry->flag, READ_DEFERRED)) { - commSetTimeout(fd, Config.Timeout.defer, NULL, NULL); - BIT_SET(entry->flag, READ_DEFERRED); - } - /* dont try reading again for a while */ - comm_set_stall(fd, 1); - return; - } else { - BIT_RESET(entry->flag, READ_DEFERRED); - } buf = get_free_4k_page(); errno = 0; /* leave one space for \0 in gopherToHTML */ @@ -833,6 +811,7 @@ gopherSendComplete(int fd, char *buf, int size, int errflag, void *data) } /* Schedule read reply. */ commSetSelect(fd, COMM_SELECT_READ, gopherReadReply, gopherState, 0); + commSetDefer(fd, protoCheckDeferRead); if (buf) put_free_4k_page(buf); /* Allocated by gopherSendRequest. */ } diff --git a/src/http.cc b/src/http.cc index a7738a9e9c..30bfe43281 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,6 @@ + /* - * $Id: http.cc,v 1.193 1997/10/22 05:50:30 wessels Exp $ + * $Id: http.cc,v 1.194 1997/10/23 05:13:40 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -616,28 +617,6 @@ httpReadReply(int fd, void *data) /* check if we want to defer reading */ clen = entry->mem_obj->inmem_hi; off = storeLowestMemReaderOffset(entry); - if ((clen - off) > READ_AHEAD_GAP) { - IOStats.Http.reads_deferred++; - debug(11, 3) ("httpReadReply: Read deferred for Object: %s\n", - entry->url); - debug(11, 3) (" Current Gap: %d bytes\n", clen - off); - /* reschedule, so it will be automatically reactivated - * when Gap is big enough. */ - commSetSelect(fd, - COMM_SELECT_READ, - httpReadReply, - httpState, 0); - /* disable read timeout until we are below the GAP */ - if (!BIT_TEST(entry->flag, READ_DEFERRED)) { - commSetTimeout(fd, Config.Timeout.defer, NULL, NULL); - BIT_SET(entry->flag, READ_DEFERRED); - } - /* dont try reading again for a while */ - comm_set_stall(fd, 1); - return; - } else { - BIT_RESET(entry->flag, READ_DEFERRED); - } errno = 0; len = read(fd, buf, SQUID_TCP_SO_RCVBUF); fd_bytes(fd, len, FD_READ); @@ -730,6 +709,7 @@ httpSendComplete(int fd, char *buf, int size, int errflag, void *data) COMM_SELECT_READ, httpReadReply, httpState, 0); + commSetDefer(fd, protoCheckDeferRead); } } diff --git a/src/main.cc b/src/main.cc index 8306cc7f71..c7b2818cf3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.175 1997/10/20 22:59:47 wessels Exp $ + * $Id: main.cc,v 1.176 1997/10/23 05:13:42 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -326,6 +326,7 @@ serverConnectionsOpen(void) continue; comm_listen(fd); commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0); + commSetDefer(fd, httpAcceptDefer); debug(1, 1) ("Accepting HTTP connections on port %d, FD %d.\n", (int) u->i, fd); HttpSockets[NHttpSockets++] = fd; diff --git a/src/protos.h b/src/protos.h index 8775862fd7..2828256e87 100644 --- a/src/protos.h +++ b/src/protos.h @@ -99,7 +99,6 @@ extern void comm_add_close_handler _PARAMS((int fd, PF *, void *)); extern void comm_remove_close_handler _PARAMS((int fd, PF *, void *)); extern int comm_udp_send _PARAMS((int fd, const char *host, u_short port, const char *buf, int len)); extern int comm_udp_sendto _PARAMS((int fd, const struct sockaddr_in *, int size, const char *buf, int len)); -extern void comm_set_stall _PARAMS((int, int)); extern void comm_write _PARAMS((int fd, char *buf, int size, @@ -108,6 +107,7 @@ extern void comm_write _PARAMS((int fd, FREE *)); extern void commCallCloseHandlers _PARAMS((int fd)); extern int commSetTimeout _PARAMS((int fd, int, PF *, void *)); +extern void commSetDefer(int fd, DEFER * func); extern void _db_init _PARAMS((const char *logfile, const char *options)); extern void _db_rotate_log _PARAMS((void)); @@ -257,6 +257,7 @@ extern void icpUdpSend _PARAMS((int fd, protocol_t)); extern PF icpHandleUdp; extern PF httpAccept; +extern DEFER httpAcceptDefer; #ifdef SQUID_SNMP extern PF snmpAccept; #endif /* SQUID_SNMP */ @@ -354,7 +355,7 @@ extern void protoDispatch _PARAMS((int, StoreEntry *, request_t *)); extern int protoUnregister _PARAMS((StoreEntry *, request_t *, struct in_addr)); extern void protoStart _PARAMS((int, StoreEntry *, peer *, request_t *)); extern int protoAbortFetch _PARAMS((StoreEntry * entry)); - +extern DEFER protoCheckDeferRead; extern void redirectStart _PARAMS((clientHttpRequest *, RH *, void *)); extern void redirectOpenServers _PARAMS((void)); diff --git a/src/stat.cc b/src/stat.cc index fd00239898..24656e35e4 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.160 1997/10/20 22:49:42 wessels Exp $ + * $Id: stat.cc,v 1.161 1997/10/23 05:13:44 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -311,8 +311,6 @@ describeFlags(const StoreEntry * entry) strcat(buf, "HI,"); if (BIT_TEST(flags, ENTRY_NEGCACHED)) strcat(buf, "NG,"); - if (BIT_TEST(flags, READ_DEFERRED)) - strcat(buf, "RD,"); if ((t = strrchr(buf, ','))) *t = '\0'; return buf; diff --git a/src/stmem.cc b/src/stmem.cc index 7c2f92b241..8533ce38e6 100644 --- a/src/stmem.cc +++ b/src/stmem.cc @@ -1,6 +1,6 @@ /* - * $Id: stmem.cc,v 1.50 1997/10/22 17:07:25 wessels Exp $ + * $Id: stmem.cc,v 1.51 1997/10/23 05:13:45 wessels Exp $ * * DEBUG: section 19 Memory Primitives * AUTHOR: Harvest Derived @@ -128,7 +128,7 @@ memFree(mem_hdr * mem) p = p->next; if (lastp) { put_free_4k_page(lastp->data); - store_mem_size -= SM_PAGE_SIZE; + store_mem_size -= SM_PAGE_SIZE; safe_free(lastp); } } diff --git a/src/structs.h b/src/structs.h index 79f0448c3e..8996830980 100644 --- a/src/structs.h +++ b/src/structs.h @@ -116,7 +116,6 @@ struct _SquidConfig { time_t neighborTimeout; struct { time_t read; - time_t defer; time_t lifetime; time_t connect; time_t request; @@ -327,7 +326,7 @@ struct _fde { void *timeout_data; void *lifetime_data; close_handler *close_handler; /* linked list */ - time_t stall_until; /* don't select for read until this time */ + DEFER *defer_check; /* check if we should defer read */ CommWriteStateData *rwstate; /* State data for comm_write */ }; @@ -496,6 +495,10 @@ struct _ConnStateData { CommWriteStateData *commWriteState; int nrequests; int persistent; + struct { + int n; + time_t until; + } defer; }; struct _ipcache_addrs { diff --git a/src/typedefs.h b/src/typedefs.h index 3e888d445b..d3bb3bbd05 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -92,6 +92,7 @@ typedef void IPH _PARAMS((const ipcache_addrs *, void *)); typedef void IRCB _PARAMS((peer *, peer_t, icp_common_t *, void *data)); typedef void PSC _PARAMS((peer *, void *)); typedef void RH _PARAMS((void *data, char *result)); +typedef int DEFER(int fd, void *data); typedef void SIH _PARAMS((int fd, void *)); /* swap in */ typedef int QS _PARAMS((const void *, const void *)); /* qsort */ diff --git a/src/wais.cc b/src/wais.cc index 15ac255854..ec41d75795 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,6 +1,6 @@ /* - * $Id: wais.cc,v 1.86 1997/10/21 19:38:54 wessels Exp $ + * $Id: wais.cc,v 1.87 1997/10/23 05:13:46 wessels Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -182,28 +182,6 @@ waisReadReply(int fd, void *data) /* check if we want to defer reading */ clen = entry->mem_obj->inmem_hi; off = storeLowestMemReaderOffset(entry); - if ((clen - off) > READ_AHEAD_GAP) { - IOStats.Wais.reads_deferred++; - debug(24, 3) ("waisReadReply: Read deferred for Object: %s\n", - entry->url); - debug(24, 3) (" Current Gap: %d bytes\n", clen - off); - /* reschedule, so it will automatically reactivated - * when Gap is big enough. */ - commSetSelect(fd, - COMM_SELECT_READ, - waisReadReply, - waisState, 0); - /* don't install read handler while we're above the gap */ - if (!BIT_TEST(entry->flag, READ_DEFERRED)) { - commSetTimeout(fd, Config.Timeout.defer, NULL, NULL); - BIT_SET(entry->flag, READ_DEFERRED); - } - /* dont try reading again for a while */ - comm_set_stall(fd, 1); - return; - } else { - BIT_RESET(entry->flag, READ_DEFERRED); - } len = read(fd, buf, 4096); fd_bytes(fd, len, FD_READ); debug(24, 5) ("waisReadReply: FD %d read len:%d\n", fd, len); @@ -290,6 +268,7 @@ waisSendComplete(int fd, char *buf, int size, int errflag, void *data) COMM_SELECT_READ, waisReadReply, waisState, 0); + commSetDefer(fd, protoCheckDeferRead); } }