From 56e64999a77d3ba692fd3610b53adfb7f94e0097 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Mon, 17 Aug 1998 22:44:02 +0000 Subject: [PATCH] further DELAY_POOLS patches from Luyer --- src/client_side.cc | 17 +---------------- src/delay_pools.cc | 25 ++++++++++++++----------- src/ftp.cc | 5 ++--- src/gopher.cc | 5 ++--- src/http.cc | 5 ++--- src/protos.h | 4 ++-- src/ssl.cc | 16 ++++++++++------ src/structs.h | 4 +++- src/tunnel.cc | 16 ++++++++++------ src/typedefs.h | 4 +--- src/wais.cc | 5 ++--- 11 files changed, 49 insertions(+), 57 deletions(-) diff --git a/src/client_side.cc b/src/client_side.cc index b3a6fe6ab4..b71179ab3e 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.379 1998/08/17 16:38:07 wessels Exp $ + * $Id: client_side.cc,v 1.380 1998/08/17 16:44:02 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -337,9 +337,6 @@ clientHandleIMSReply(void *data, char *buf, ssize_t size) storeUnlockObject(entry); entry = http->entry = http->old_entry; entry->refcount++; -#if DELAY_POOLS - http->request->delay_id = 0; -#endif } else if (STORE_PENDING == entry->store_status && 0 == status) { debug(33, 3) ("clientHandleIMSReply: Incomplete headers for '%s'\n", url); if (size >= 4096) { @@ -351,9 +348,6 @@ clientHandleIMSReply(void *data, char *buf, ssize_t size) storeUnlockObject(entry); entry = http->entry = http->old_entry; entry->refcount++; -#if DELAY_POOLS - http->request->delay_id = 0; -#endif /* continue */ } else { storeClientCopy(entry, @@ -389,9 +383,6 @@ clientHandleIMSReply(void *data, char *buf, ssize_t size) requestUnlink(entry->mem_obj->request); entry->mem_obj->request = NULL; } -#if DELAY_POOLS - http->request->delay_id = 0; -#endif } else { /* the client can handle this reply, whatever it is */ http->log_type = LOG_TCP_REFRESH_MISS; @@ -1140,9 +1131,6 @@ clientCacheHit(void *data, char *buf, ssize_t size) assert(http->log_type == LOG_TCP_HIT); if (checkNegativeHit(e)) { http->log_type = LOG_TCP_NEGATIVE_HIT; -#if DELAY_POOLS - http->request->delay_id = 0; -#endif clientSendMoreData(data, buf, size); } else if (refreshCheck(e, r, 0) && !http->flags.internal) { /* @@ -1194,9 +1182,6 @@ clientCacheHit(void *data, char *buf, ssize_t size) */ if (e->mem_status == IN_MEMORY) http->log_type = LOG_TCP_MEM_HIT; -#if DELAY_POOLS - http->request->delay_id = 0; -#endif clientSendMoreData(data, buf, size); } } diff --git a/src/delay_pools.cc b/src/delay_pools.cc index eb3abd1a6a..76e38cf25e 100644 --- a/src/delay_pools.cc +++ b/src/delay_pools.cc @@ -1,6 +1,6 @@ /* - * $Id: delay_pools.cc,v 1.2 1998/08/14 09:22:34 wessels Exp $ + * $Id: delay_pools.cc,v 1.3 1998/08/17 16:44:03 wessels Exp $ * * DEBUG: section 77 Delay Pools * AUTHOR: David Luyer @@ -38,7 +38,6 @@ #if DELAY_POOLS #include "squid.h" - struct _delayData { int class1_aggregate; int class2_aggregate; @@ -72,7 +71,8 @@ int delayClient(clientHttpRequest * http) { aclCheck_t ch; - int i, j; + int i; + int j; unsigned int host; unsigned char net; unsigned char class = 0; @@ -340,7 +340,7 @@ delayPoolsInit(void) * into account bytes already buffered - that is up to the caller. */ int -delayBytesWanted(delay_id d, int max) +delayBytesWanted(delay_id d, int min, int max) { int position = d & 0xFFFF; unsigned char class = (d & 0xFF0000) >> 16; @@ -374,15 +374,16 @@ delayBytesWanted(delay_id d, int max) fatalf("delayBytesWanted: Invalid class %d\n", class); break; } - assert(nbytes > 0); + nbytes = XMAX(min, nbytes); + assert(nbytes >= min); assert(nbytes <= max); return nbytes; } /* * this records actual bytes recieved. always recorded, even if the - * class is disabled - see above for all the cases which would be needed - * to efficiently not record it, so it's just ignored if not wanted. + * class is disabled - it's more efficient to just do it than to do all + * the checks. */ void delayBytesIn(delay_id d, int qty) @@ -413,22 +414,24 @@ int delayMostBytesWanted(const MemObject * mem, int max) { int i = 0; + int found = 0; store_client *sc; for (sc = mem->clients; sc; sc = sc->next) { if (sc->callback_data == NULL) /* open slot */ continue; if (sc->type != STORE_MEM_CLIENT) continue; - i = XMAX(delayBytesWanted(sc->delay_id, max), i); + i = delayBytesWanted(sc->delay_id, i, max); + found = 1; } - return i; + return found ? i : max; } delay_id delayMostBytesAllowed(const MemObject * mem) { int j; - int jmax = 0; + int jmax = -1; store_client *sc; delay_id d = 0; for (sc = mem->clients; sc; sc = sc->next) { @@ -436,7 +439,7 @@ delayMostBytesAllowed(const MemObject * mem) continue; if (sc->type != STORE_MEM_CLIENT) continue; - j = delayBytesWanted(sc->delay_id, SQUID_TCP_SO_RCVBUF); + j = delayBytesWanted(sc->delay_id, 0, SQUID_TCP_SO_RCVBUF); if (j > jmax) { jmax = j; d = sc->delay_id; diff --git a/src/ftp.cc b/src/ftp.cc index 0f64c779ce..ce497ee69e 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.244 1998/08/14 19:25:19 wessels Exp $ + * $Id: ftp.cc,v 1.245 1998/08/17 16:44:04 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -806,8 +806,7 @@ ftpDataRead(int fd, void *data) errno = 0; read_sz = ftpState->data.size - ftpState->data.offset; #if DELAY_POOLS - read_sz = delayBytesWanted(delay_id, read_sz); - assert(read_sz > 0); + read_sz = delayBytesWanted(delay_id, 1, read_sz); #endif memset(ftpState->data.buf + ftpState->data.offset, '\0', read_sz); len = read(fd, ftpState->data.buf + ftpState->data.offset, read_sz); diff --git a/src/gopher.cc b/src/gopher.cc index 2885e7ef6a..cca17d195c 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,7 +1,7 @@ /* - * $Id: gopher.cc,v 1.135 1998/08/14 09:22:36 wessels Exp $ + * $Id: gopher.cc,v 1.136 1998/08/17 16:44:06 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -609,8 +609,7 @@ gopherReadReply(int fd, void *data) buf = memAllocate(MEM_4K_BUF); read_sz = 4096 - 1; /* leave room for termination */ #if DELAY_POOLS - read_sz = delayBytesWanted(delay_id, read_sz); - assert(read_sz > 0); + read_sz = delayBytesWanted(delay_id, 1, read_sz); #endif /* leave one space for \0 in gopherToHTML */ len = read(fd, buf, read_sz); diff --git a/src/http.cc b/src/http.cc index 4926fff502..f87a9c0d4c 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.306 1998/08/14 19:25:20 wessels Exp $ + * $Id: http.cc,v 1.307 1998/08/17 16:44:07 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -373,8 +373,7 @@ httpReadReply(int fd, void *data) errno = 0; read_sz = SQUID_TCP_SO_RCVBUF; #if DELAY_POOLS - read_sz = delayBytesWanted(delay_id, read_sz); - assert(read_sz > 0); + read_sz = delayBytesWanted(delay_id, 1, read_sz); #endif len = read(fd, buf, read_sz); debug(11, 5) ("httpReadReply: FD %d: len %d.\n", fd, len); diff --git a/src/protos.h b/src/protos.h index cc6dec8335..fb93f5931e 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.247 1998/08/14 23:53:09 wessels Exp $ + * $Id: protos.h,v 1.248 1998/08/17 16:44:09 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1066,7 +1066,7 @@ extern int delayMostBytesWanted(const MemObject * mem, int max); extern int delayMostBytesAllowed(const MemObject * mem); extern void delayBytesIn(delay_id, int qty); extern void delaySetStoreClient(StoreEntry * e, void *data, delay_id delay_id); -extern int delayBytesWanted(delay_id d, int max); +extern int delayBytesWanted(delay_id d, int min, int max); #endif /* diff --git a/src/ssl.cc b/src/ssl.cc index 71271f8e18..cbb63e2840 100644 --- a/src/ssl.cc +++ b/src/ssl.cc @@ -1,6 +1,6 @@ /* - * $Id: ssl.cc,v 1.86 1998/08/14 09:22:40 wessels Exp $ + * $Id: ssl.cc,v 1.87 1998/08/17 16:44:11 wessels Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -113,7 +113,7 @@ static int sslDeferServerRead(int fdnotused, void *data) { request_t *r = data; - return delayBytesWanted(r->delay_id, 1) == 0; + return delayBytesWanted(r->delay_id, 0, 1) == 0; } #endif @@ -149,8 +149,13 @@ sslSetSelect(SslStateData * sslState) 0); } #if DELAY_POOLS - read_sz = delayBytesWanted(sslState->request->delay_id, read_sz); - assert(read_sz > 0); + /* If this was allowed to return 0, there would be a possibility + * of the socket becoming "hung" with data accumulating but no + * write handler (server.len==0) and no read handler (!(0<0)) and + * no data flowing in the other direction. Hence the argument of + * 1 as min. + */ + read_sz = delayBytesWanted(sslState->request->delay_id, 1, read_sz); #endif if (sslState->server.len < read_sz) { /* Have room to read more */ @@ -179,8 +184,7 @@ sslReadServer(int fd, void *data) fd, read_sz, sslState->server.len); errno = 0; #if DELAY_POOLS - read_sz = delayBytesWanted(sslState->request->delay_id, read_sz); - assert(read_sz > 0); + read_sz = delayBytesWanted(sslState->request->delay_id, 1, read_sz); #endif len = read(fd, sslState->server.buf + sslState->server.len, read_sz); debug(26, 3) ("sslReadServer: FD %d, read %d bytes\n", fd, len); diff --git a/src/structs.h b/src/structs.h index 0562175b77..24460f30ec 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.198 1998/08/16 06:35:18 wessels Exp $ + * $Id: structs.h,v 1.199 1998/08/17 16:44:12 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -201,10 +201,12 @@ struct _relist { relist *next; }; +#if DELAY_POOLS struct _delay_spec { int restore_bps; int max_bytes; }; +#endif struct _SquidConfig { struct { diff --git a/src/tunnel.cc b/src/tunnel.cc index 90ab422ff3..39983821a6 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -1,6 +1,6 @@ /* - * $Id: tunnel.cc,v 1.86 1998/08/14 09:22:40 wessels Exp $ + * $Id: tunnel.cc,v 1.87 1998/08/17 16:44:11 wessels Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -113,7 +113,7 @@ static int sslDeferServerRead(int fdnotused, void *data) { request_t *r = data; - return delayBytesWanted(r->delay_id, 1) == 0; + return delayBytesWanted(r->delay_id, 0, 1) == 0; } #endif @@ -149,8 +149,13 @@ sslSetSelect(SslStateData * sslState) 0); } #if DELAY_POOLS - read_sz = delayBytesWanted(sslState->request->delay_id, read_sz); - assert(read_sz > 0); + /* If this was allowed to return 0, there would be a possibility + * of the socket becoming "hung" with data accumulating but no + * write handler (server.len==0) and no read handler (!(0<0)) and + * no data flowing in the other direction. Hence the argument of + * 1 as min. + */ + read_sz = delayBytesWanted(sslState->request->delay_id, 1, read_sz); #endif if (sslState->server.len < read_sz) { /* Have room to read more */ @@ -179,8 +184,7 @@ sslReadServer(int fd, void *data) fd, read_sz, sslState->server.len); errno = 0; #if DELAY_POOLS - read_sz = delayBytesWanted(sslState->request->delay_id, read_sz); - assert(read_sz > 0); + read_sz = delayBytesWanted(sslState->request->delay_id, 1, read_sz); #endif len = read(fd, sslState->server.buf + sslState->server.len, read_sz); debug(26, 3) ("sslReadServer: FD %d, read %d bytes\n", fd, len); diff --git a/src/typedefs.h b/src/typedefs.h index 2fea3951fa..978c735373 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.67 1998/08/14 09:22:41 wessels Exp $ + * $Id: typedefs.h,v 1.68 1998/08/17 16:44:13 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -228,6 +228,4 @@ typedef void (*ObjPackMethod) (void *obj, Packer * p); #if DELAY_POOLS typedef int delay_id; -#else -typedef int delay_id; #endif diff --git a/src/wais.cc b/src/wais.cc index 7f068e1a80..ef540f8729 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,6 +1,6 @@ /* - * $Id: wais.cc,v 1.116 1998/08/14 09:22:43 wessels Exp $ + * $Id: wais.cc,v 1.117 1998/08/17 16:44:14 wessels Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -101,8 +101,7 @@ waisReadReply(int fd, void *data) errno = 0; read_sz = 4096; #if DELAY_POOLS - read_sz = delayBytesWanted(delay_id, read_sz); - assert(read_sz > 0); + read_sz = delayBytesWanted(delay_id, 1, read_sz); #endif len = read(fd, buf, read_sz); if (len > 0) { -- 2.47.3