]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
further DELAY_POOLS patches from Luyer
authorwessels <>
Mon, 17 Aug 1998 22:44:02 +0000 (22:44 +0000)
committerwessels <>
Mon, 17 Aug 1998 22:44:02 +0000 (22:44 +0000)
src/client_side.cc
src/delay_pools.cc
src/ftp.cc
src/gopher.cc
src/http.cc
src/protos.h
src/ssl.cc
src/structs.h
src/tunnel.cc
src/typedefs.h
src/wais.cc

index b3a6fe6ab4113edcbc8938372c5ed77aa5171af6..b71179ab3e4ebc4e7968c9584ed0718849bf21d5 100644 (file)
@@ -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);
     }
 }
index eb3abd1a6a1e038ed6e31bc9226024ad0ce91d13..76e38cf25e2eeda31c96c95d3c249dc54f6323e4 100644 (file)
@@ -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 <luyer@ucs.uwa.edu.au>
@@ -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;
index 0f64c779ce18757ef5ea674d8875143d28371f04..ce497ee69eabb771902ef5135e72ac7c02bb5688 100644 (file)
@@ -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);
index 2885e7ef6a630cc8ebfa723a294dd70fd640e888..cca17d195cb09b523b25d580765db5365c9d20a8 100644 (file)
@@ -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);
index 4926fff50258a709499478bb9b93f4c897b6e36f..f87a9c0d4cebafc7b2dc4b17117cdd53b4eb962f 100644 (file)
@@ -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);
index cc6dec8335778331d04d92c28b5afc9c1fec2e41..fb93f5931ecf2886eae3e87d5091c0deab7d6f1e 100644 (file)
@@ -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
 
 /*
index 71271f8e18fa78ef3cbdcf21ee0dbbbcb225e1f9..cbb63e28408b2ee8fc15902ff12bdf31ed43969c 100644 (file)
@@ -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);
index 0562175b77f9808ac2bd63c84c079ef4167644c7..24460f30ec12b9ba84ae9696fc97117c4349b747 100644 (file)
@@ -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 {
index 90ab422ff31b4e1541556b8c6094ca3e69617aab..39983821a6261038e9cb326a2fb704641683c793 100644 (file)
@@ -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);
index 2fea3951fab7f6cd66c4330b245e3870175a47c0..978c7353733695aef8f4c0de1477ba145c8fab0a 100644 (file)
@@ -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
index 7f068e1a80a04c851efdc6c8379e691224332354..ef540f8729c2b1cc87339f298c0eb975ac9ed761 100644 (file)
@@ -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) {