]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
-Fix calling maintenance functions in main. Don't rely on COMM_TIMEOUT
authorwessels <>
Tue, 27 Aug 1996 11:51:36 +0000 (11:51 +0000)
committerwessels <>
Tue, 27 Aug 1996 11:51:36 +0000 (11:51 +0000)
 and clean_rate stuff.

src/comm.cc
src/main.cc
src/stat.cc

index dc9e445860d14840f7d8f5e083f900a398578701..12d59d75bb45d716cff3e890167fc3483161940a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.58 1996/08/26 19:57:03 wessels Exp $
+ * $Id: comm.cc,v 1.59 1996/08/27 05:51:36 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -657,9 +657,8 @@ static void comm_select_incoming()
 
 
 /* Select on all sockets; call handlers for those that are ready. */
-int comm_select(sec, failtime)
+int comm_select(sec)
      time_t sec;
-     time_t failtime;
 {
     fd_set exceptfds;
     fd_set readfds;
@@ -683,9 +682,6 @@ int comm_select(sec, failtime)
     do {
        if (sec > 60)
            fatal_dump(NULL);
-       if (0 < failtime && failtime < squid_curtime)
-           break;
-
        FD_ZERO(&readfds);
        FD_ZERO(&writefds);
        FD_ZERO(&exceptfds);
index 2324b04c45abcb8778c16d6b67789090269f82e3..7713bebd24fb22781d68f13e313fdec62f852dc8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.cc,v 1.63 1996/08/26 22:47:54 wessels Exp $
+ * $Id: main.cc,v 1.64 1996/08/27 05:51:38 wessels Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
 #include "squid.h"
 
 time_t squid_starttime = 0;
-time_t next_cleaning = 0;
 int theHttpConnection = -1;
 int theInIcpConnection = -1;
 int theOutIcpConnection = -1;
@@ -140,6 +139,11 @@ static int malloc_debug_level = 0;
 #endif
 static void rotate_logs _PARAMS((int));
 static void reconfigure _PARAMS((int));
+static void mainInitialize _PARAMS((void));
+static void mainRenitialize _PARAMS((void));
+static void mainMaintenance _PARAMS((void));
+static void usage _PARAMS((void));
+static void mainParseOptions _PARAMS((int, char **));
 
 static void usage()
 {
@@ -480,15 +484,56 @@ static void mainInitialize()
 }
 
 
+static void mainMaintenance()
+{
+    static time_t last_cleaning = 0;
+    static time_t last_maintain = 0;
+    static time_t last_dirclean = 0;
+    static time_t last_announce = 0;
+    static time_t last_ip_purge = 0;
+    int n;
+    if (squid_curtime > last_maintain) {
+       storeMaintainSwapSpace();
+       last_maintain = squid_curtime;
+       return;
+    }
+    if (squid_curtime >= last_dirclean + 15
+       && store_rebuilding == STORE_NOT_REBUILDING) {
+       /* clean a cache directory every 15 seconds */
+       /* 15 * 16 * 256 = 17 hrs */
+       storeDirClean();
+       last_dirclean = squid_curtime;
+       return;
+    }
+    if (squid_curtime >= last_ip_purge + 10) {
+       ipcache_purgelru();
+       last_ip_purge = squid_curtime;
+       return;
+    }
+    if (Config.cleanRate > 0) {
+       if (squid_curtime >= last_cleaning + Config.cleanRate) {
+           debug(1, 1, "Performing a garbage collection...\n");
+           n = storePurgeOld();
+           debug(1, 1, "Garbage collection done, %d objects removed\n", n);
+           last_cleaning = squid_curtime + Config.cleanRate;
+           return;
+       }
+    }
+    if (Config.Announce.rate > 0) {
+       if (squid_curtime >= last_announce + Config.Announce.rate) {
+           send_announce();
+           last_announce = squid_curtime;
+           return;
+       }
+    }
+}
+
 int main(argc, argv)
      int argc;
      char **argv;
 {
     int errcount = 0;
     int n;                     /* # of GC'd objects */
-    time_t last_maintain = 0;
-    time_t last_dirclean = 0;
-    time_t last_announce = 0;
     time_t loop_delay;
 
     /* call mallopt() before anything else */
@@ -542,22 +587,9 @@ int main(argc, argv)
     mainInitialize();
 
     /* main loop */
-    if (Config.cleanRate > 0)
-       next_cleaning = time(NULL) + Config.cleanRate;
     for (;;) {
        loop_delay = (time_t) 10;
-       /* maintain cache storage */
-       if (squid_curtime > last_maintain) {
-           storeMaintainSwapSpace();
-           last_maintain = squid_curtime;
-       }
-       if (squid_curtime - last_dirclean > 15
-           && store_rebuilding == STORE_NOT_REBUILDING) {
-           /* clean a cache directory every 15 seconds */
-           /* 15 * 16 * 256 = 17 hrs */
-           storeDirClean();
-           last_dirclean = squid_curtime;
-       }
+       mainMaintenance();
        if (rotate_pending) {
            ftpServerClose();
            _db_rotate_log();   /* cache.log */
@@ -570,7 +602,7 @@ int main(argc, argv)
        /* do background processing */
        if (doBackgroundProcessing())
            loop_delay = (time_t) 0;
-       switch (comm_select(loop_delay, next_cleaning)) {
+       switch (comm_select(loop_delay)) {
        case COMM_OK:
            errcount = 0;       /* reset if successful */
            break;
@@ -580,21 +612,6 @@ int main(argc, argv)
            if (errcount == 10)
                fatal_dump("Select Loop failed!");
            break;
-       case COMM_TIMEOUT:
-           if (Config.cleanRate > 0 && squid_curtime >= next_cleaning) {
-               debug(1, 1, "Performing a garbage collection...\n");
-               n = storePurgeOld();
-               debug(1, 1, "Garbage collection done, %d objects removed\n", n);
-               next_cleaning = squid_curtime + Config.cleanRate;
-           }
-           if ((n = Config.Announce.rate) > 0) {
-               if (squid_curtime > last_announce + n)
-                   send_announce();
-               last_announce = squid_curtime;
-           }
-           ipcache_purgelru();
-           /* house keeping */
-           break;
        case COMM_SHUTDOWN:
            /* delayed close so we can transmit while shutdown pending */
            if (theOutIcpConnection > 0) {
@@ -611,6 +628,8 @@ int main(argc, argv)
                fatal_dump("MAIN: SHUTDOWN from comm_select, but nothing pending.");
            }
            break;
+       case COMM_TIMEOUT:
+               break;
        default:
            fatal_dump("MAIN: Internal error -- this should never happen.");
            break;
index 2214cb320fca42d1bf93d99feaf66af71989f843..23bed56054a6f328da392e49612a22671472fcd9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: stat.cc,v 1.54 1996/08/26 22:47:57 wessels Exp $
+ * $Id: stat.cc,v 1.55 1996/08/27 05:51:38 wessels Exp $
  *
  * DEBUG: section 18    Cache Manager Statistics
  * AUTHOR: Harvest Derived
@@ -659,8 +659,6 @@ void info_get(obj, sentry)
        storeGetSwapSize() >> 10);
     storeAppendPrintf(sentry, "{\tStorage Mem size:\t%d KB}\n",
        storeGetMemSize() >> 10);
-    tod = mkrfc850(&next_cleaning);
-    storeAppendPrintf(sentry, "{\tStorage Expiration at:\t%s}\n", tod);
 
 #if HAVE_GETRUSAGE && defined(RUSAGE_SELF)
     storeAppendPrintf(sentry, "{Resource usage for %s:}\n", appname);