]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
More work on persistent connections
authorwessels <>
Sun, 10 Aug 1997 12:34:26 +0000 (12:34 +0000)
committerwessels <>
Sun, 10 Aug 1997 12:34:26 +0000 (12:34 +0000)
- added histogram counter
- added httpRestart() to retry failed requests when the
  server closes on us.
- missing commSetTimeout() calls when reusing a pconn.
- need to disable read and timeout handler when pconn
  pops a FD.
- const fixes

src/cbdata.cc
src/client.cc
src/comm.cc
src/dns.cc
src/errorpage.cc
src/http.cc
src/pconn.cc
src/protos.h
src/stat.cc
src/structs.h
src/url.cc

index ee3583e3b62815298eabd041657619a229d2b9c8..1a64b636ce6be3cb5934f003d7495f3bfb1c9605 100644 (file)
@@ -59,7 +59,7 @@ cbdataFree(void *p)
     c->valid = 0;
     if (c->locks) {
        debug(45, 3) ("cbdataFree: %p has %d locks, not freeing\n",
-               p, c->locks);
+           p, c->locks);
        return;
     }
     hash_remove_link(htable, (hash_link *) c);
index 9ca67a0bf8c70783d4a11974444cf6eadcf17daa..662e055faf21274d6eb53a2c6f8c2d4d55ad5170 100644 (file)
@@ -1,6 +1,7 @@
 
+
 /*
- * $Id: client.cc,v 1.24 1997/08/10 04:42:34 wessels Exp $
+ * $Id: client.cc,v 1.25 1997/08/10 06:34:27 wessels Exp $
  *
  * DEBUG: section 0     WWW Client
  * AUTHOR: Harvest Derived
index 0d2f644c5b21c8d04a8e93848f30991a35192929..25880e924ef8029a9fec4b14c0391626ec0cf84b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: comm.cc,v 1.184 1997/08/10 04:42:36 wessels Exp $
+ * $Id: comm.cc,v 1.185 1997/08/10 06:34:27 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -332,7 +332,7 @@ commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *
     cs->port = port;
     cs->callback = callback;
     cs->data = data;
-    cbdataLock(data);
+    cbdataLock(cs->data);
     comm_add_close_handler(fd, commConnectFree, cs);
     cs->locks++;
     ipcache_nbgethostbyname(host, commConnectDnsHandle, cs);
@@ -363,7 +363,7 @@ commConnectCallback(ConnectStateData * cs, int status)
     commConnectFree(fd, cs);
     if (cbdataValid(data))
        callback(fd, status, data);
-    cbdataUnlock(data);
+    cbdataUnlock(cs->data);
 }
 
 static void
@@ -579,13 +579,12 @@ comm_close(int fd)
     assert(fd >= 0);
     assert(fd < Squid_MaxFD);
     F = &fd_table[fd];
-    if (!F->open) {
-       debug(5, 1) ("comm_close: FD %d is not open!\n", fd);
-       return;
-    }
+    assert(F->open);
     assert(F->type != FD_FILE);
     CommWriteStateCallbackAndFree(fd, COMM_ERROR);
     commCallCloseHandlers(fd);
+    if (F->uses)               /* assume persistent connect count */
+       pconnHistCount(1, F->uses);
     fd_close(fd);              /* update fdstat */
 #if USE_ASYNC_IO
     aioClose(fd);
index 1018ec287c6004fb836b39db2d0691ff87d0fb7b..41c5d3e68b658dd80a2e7d567feda7d601fd6980 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: dns.cc,v 1.39 1997/07/26 04:48:28 wessels Exp $
+ * $Id: dns.cc,v 1.40 1997/08/10 06:34:28 wessels Exp $
  *
  * DEBUG: section 34    Dnsserver interface
  * AUTHOR: Harvest Derived
@@ -132,7 +132,7 @@ dnsOpenServer(const char *command)
        0,
        COMM_NOCLOEXEC,
        "dnsserver listen socket");
-    if (cfd == COMM_ERROR) {
+    if (cfd < 0) {
        debug(34, 0) ("dnsOpenServer: Failed to create dnsserver\n");
        return -1;
     }
index 1cdd354d791e909cfcd37f462d8a9fa7f2becd59..83f38cefbebddeaf7bdd293b9a9d24c81a8a86ba 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: errorpage.cc,v 1.62 1997/08/10 04:42:37 wessels Exp $
+ * $Id: errorpage.cc,v 1.63 1997/08/10 06:34:29 wessels Exp $
  *
  * DEBUG: section 4     Error Generation
  * AUTHOR: Duane Wessels
@@ -185,7 +185,7 @@ errorSend(int fd, ErrorState * err)
 }
 
 void
-errorAppendEntry(const StoreEntry * entry, ErrorState * err)
+errorAppendEntry(StoreEntry * entry, ErrorState * err)
 {
     char *buf;
     int len;
index 54812e1aaf51433905f85cbd812791b3116a893d..eb910412965af8f6bac6a607334c7d973f30409c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: http.cc,v 1.181 1997/08/10 04:42:38 wessels Exp $
+ * $Id: http.cc,v 1.182 1997/08/10 06:34:29 wessels Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -211,10 +211,11 @@ static void httpMakePublic _PARAMS((StoreEntry *));
 static char *httpStatusString _PARAMS((int status));
 static STABH httpAbort;
 static HttpStateData *httpBuildState _PARAMS((int, StoreEntry *, request_t *, peer *));
-static int httpSocketOpen _PARAMS((StoreEntry *, const request_t *));
+static int httpSocketOpen _PARAMS((StoreEntry *, request_t *));
+static void httpRestart _PARAMS((HttpStateData *));
 
 static void
-httpStateFree(int fdunused, void *data)
+httpStateFree(int fd, void *data)
 {
     HttpStateData *httpState = data;
     if (httpState == NULL)
@@ -668,15 +669,19 @@ httpReadReply(int fd, void *data)
        debug(50, 2) ("httpReadReply: FD %d: read failure: %s.\n",
            fd, xstrerror());
     } else if (len == 0 && entry->mem_obj->e_current_len == 0) {
-       httpState->eof = 1;
-       err = xcalloc(1, sizeof(ErrorState));
-       err->type = ERR_ZERO_SIZE_OBJECT;
-       err->errno = errno;
-       err->http_status = HTTP_SERVICE_UNAVAILABLE;
-       err->request = requestLink(httpState->request);
-       errorAppendEntry(entry, err);
-       storeAbort(entry, 0);
-       comm_close(fd);
+       if (fd_table[fd].uses > 1) {
+           httpRestart(httpState);
+       } else {
+           httpState->eof = 1;
+           err = xcalloc(1, sizeof(ErrorState));
+           err->type = ERR_ZERO_SIZE_OBJECT;
+           err->errno = errno;
+           err->http_status = HTTP_SERVICE_UNAVAILABLE;
+           err->request = requestLink(httpState->request);
+           errorAppendEntry(entry, err);
+           storeAbort(entry, 0);
+           comm_close(fd);
+       }
     } else if (len == 0) {
        /* Connection closed; retrieval done. */
        httpState->eof = 1;
@@ -947,7 +952,7 @@ httpSendRequest(int fd, void *data)
 }
 
 static int
-httpSocketOpen(StoreEntry * entry, const request_t * request)
+httpSocketOpen(StoreEntry * entry, request_t * request)
 {
     int fd;
     ErrorState *err;
@@ -1015,6 +1020,10 @@ httpStart(request_t * request, StoreEntry * entry, peer * e)
        if ((fd = pconnPop(e->host, e->http_port)) >= 0) {
            debug(0, 0) ("httpStart: reusing pconn FD %d\n", fd);
            httpState = httpBuildState(fd, entry, request, e);
+           commSetTimeout(httpState->fd,
+               Config.Timeout.connect,
+               httpTimeout,
+               httpState);
            httpConnectDone(fd, COMM_OK, httpState);
            return;
        }
@@ -1022,6 +1031,10 @@ httpStart(request_t * request, StoreEntry * entry, peer * e)
        if ((fd = pconnPop(request->host, request->port)) >= 0) {
            debug(0, 0) ("httpStart: reusing pconn FD %d\n", fd);
            httpState = httpBuildState(fd, entry, request, e);
+           commSetTimeout(httpState->fd,
+               Config.Timeout.connect,
+               httpTimeout,
+               httpState);
            httpConnectDone(fd, COMM_OK, httpState);
            return;
        }
@@ -1041,6 +1054,31 @@ httpStart(request_t * request, StoreEntry * entry, peer * e)
        httpState);
 }
 
+static void
+httpRestart(HttpStateData * httpState)
+{
+    /* restart a botched request from a persistent connection */
+    debug(0, 0) ("Retrying HTTP request for %s\n", httpState->entry->url);
+    if (httpState->fd >= 0) {
+       comm_remove_close_handler(httpState->fd, httpStateFree, httpState);
+       comm_close(httpState->fd);
+       httpState->fd = -1;
+    }
+    httpState->fd = httpSocketOpen(httpState->entry, httpState->request);
+    if (httpState->fd < 0)
+       return;
+    comm_add_close_handler(httpState->fd, httpStateFree, httpState);
+    commSetTimeout(httpState->fd,
+       Config.Timeout.connect,
+       httpTimeout,
+       httpState);
+    commConnectStart(httpState->fd,
+       httpState->request->host,
+       httpState->request->port,
+       httpConnectDone,
+       httpState);
+}
+
 static void
 httpConnectDone(int fd, int status, void *data)
 {
@@ -1073,6 +1111,7 @@ httpConnectDone(int fd, int status, void *data)
        comm_close(fd);
     } else {
        fd_note(fd, entry->url);
+       fd_table[fd].uses++;
        commSetSelect(fd, COMM_SELECT_WRITE, httpSendRequest, httpState, 0);
     }
 }
index d18404b296a0d627bd9898b907d53fb73c3bc97e..03419f6b65ba29e80299fdc2ea41be9e55f9230c 100644 (file)
@@ -133,6 +133,8 @@ pconnPop(const char *host, u_short port)
        assert(p->nfds > 0);
        fd = p->fds[0];
        pconnRemoveFD(p, fd);
+       commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0);
+       commSetTimeout(fd, -1, NULL, NULL);
     }
     xfree(key);
     return fd;
index 3b0b840d067262d196e089dc5bed3995a051df31..b9969eb462749ce2e4f0ebc830b2df6dcbdd71e2 100644 (file)
@@ -527,7 +527,7 @@ extern method_t urlParseMethod _PARAMS((const char *));
 extern void urlInitialize _PARAMS((void));
 extern request_t *urlParse _PARAMS((method_t, char *));
 extern char *urlCanonical _PARAMS((const request_t *, char *));
-extern request_t *requestLink _PARAMS((const request_t *));
+extern request_t *requestLink _PARAMS((request_t *));
 extern void requestUnlink _PARAMS((request_t *));
 extern int matchDomainName _PARAMS((const char *d, const char *h));
 extern int urlCheckRequest _PARAMS((const request_t *));
@@ -542,7 +542,7 @@ extern void logUserAgent _PARAMS((const char *, const char *));
 extern peer_t parseNeighborType _PARAMS((const char *s));
 
 extern void errorSend _PARAMS((int fd, ErrorState *));
-extern void errorAppendEntry _PARAMS((const StoreEntry *, ErrorState *));
+extern void errorAppendEntry _PARAMS((StoreEntry *, ErrorState *));
 extern void errorInitialize _PARAMS((void));
 
 extern OBJH stat_io_get;
index 6e7ad68c7e80c371ef3d918183a540f5cc0dcb90..e38fb5136ff9bf6d29d003f2e058e9d202413e1a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: stat.cc,v 1.153 1997/08/10 04:42:47 wessels Exp $
+ * $Id: stat.cc,v 1.154 1997/08/10 06:34:32 wessels Exp $
  *
  * DEBUG: section 18    Cache Manager Statistics
  * AUTHOR: Harvest Derived
@@ -139,6 +139,7 @@ static void info_get_mallstat _PARAMS((int, int, StoreEntry *));
 
 #define PCONN_HIST_SZ 256
 int client_pconn_hist[PCONN_HIST_SZ];
+int server_pconn_hist[PCONN_HIST_SZ];
 
 /* process utilization information */
 static void
@@ -887,8 +888,10 @@ stat_init(cacheinfo ** object, const char *logfilename)
        obj->proto_stat_data[i].kb.now = 0;
     }
     *object = obj;
-    for (i = 0; i < PCONN_HIST_SZ; i++)
+    for (i = 0; i < PCONN_HIST_SZ; i++) {
        client_pconn_hist[i] = 0;
+       server_pconn_hist[i] = 0;
+    }
 }
 
 void
@@ -899,6 +902,10 @@ pconnHistCount(int what, int i)
     /* what == 0 for client, 1 for server */
     if (what == 0)
        client_pconn_hist[i]++;
+    else if (what == 1)
+       server_pconn_hist[i]++;
+    else
+       fatal_dump("pconnHistCount: bad 'what' arg");
 }
 
 void
@@ -908,12 +915,24 @@ pconnHistDump(StoreEntry * e)
     storeAppendPrintf(e,
        "Client-side persistent connection counts:\n"
        "\n"
-       "req/\n"
-       "conn      count\n"
-       "----  ---------\n");
+       "\treq/\n"
+       "\tconn      count\n"
+       "\t----  ---------\n");
     for (i = 0; i < PCONN_HIST_SZ; i++) {
        if (client_pconn_hist[i] == 0)
            continue;
-       storeAppendPrintf(e, "%4d  %9d\n", i, client_pconn_hist[i]);
+       storeAppendPrintf(e, "\t%4d  %9d\n", i, client_pconn_hist[i]);
+    }
+    storeAppendPrintf(e,
+       "\n"
+       "Server-side persistent connection counts:\n"
+       "\n"
+       "\treq/\n"
+       "\tconn      count\n"
+       "\t----  ---------\n");
+    for (i = 0; i < PCONN_HIST_SZ; i++) {
+       if (server_pconn_hist[i] == 0)
+           continue;
+       storeAppendPrintf(e, "\t%4d  %9d\n", i, server_pconn_hist[i]);
     }
 }
index 0cd76761dfb8a7f4adb861efb6fd3470dd4657db..e6dd6d454b3fcef7ce2f6693326d4adbad89b630 100644 (file)
@@ -302,6 +302,7 @@ struct _fde {
     int flags;
     int bytes_read;
     int bytes_written;
+    int uses;                  /* ie # req's over persistent conn */
     struct _fde_disk {
        DWCB *wrt_handle;
        void *wrt_handle_data;
index f03d87692367fceaa0d7c3cc69a6adc5b0627652..46a9dca91f623cf9f0f5987d7846da7967ca0ab8 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: url.cc,v 1.61 1997/08/10 04:42:50 wessels Exp $
+ * $Id: url.cc,v 1.62 1997/08/10 06:34:33 wessels Exp $
  *
  * DEBUG: section 23    URL Parsing
  * AUTHOR: Duane Wessels
@@ -338,7 +338,7 @@ urlClean(char *dirty)
 
 
 request_t *
-requestLink(const request_t * request)
+requestLink(request_t * request)
 {
     request->link_count++;
     return request;