]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Move *ConnectionOpen() functionality to client_side.c and icp_v2.c.
authorwessels <>
Sun, 23 Nov 1997 13:50:26 +0000 (13:50 +0000)
committerwessels <>
Sun, 23 Nov 1997 13:50:26 +0000 (13:50 +0000)
trying to make it so HUP doesn't require closing all the connections

src/client_side.cc
src/icp_v2.cc
src/main.cc

index 17c94d8bf71ee15fe214a1804a8e6268ce918d46..41d788a9835b083139c64009e53d34525838c322 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.156 1997/11/21 17:51:46 wessels Exp $
+ * $Id: client_side.cc,v 1.157 1997/11/23 06:50:27 wessels Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -1866,3 +1866,32 @@ checkFailureRatio(log_type rcode, hier_code hcode)
     fail_ratio = 0.8;          /* reset to something less than 1.0 */
 }
 #endif
+
+void
+clientHttpConnectionsOpen(void)
+{
+    ushortlist *u;
+    int fd;
+debug(0,0)("clientHttpConnectionsOpen\n");
+    for (u = Config.Port.http; u; u = u->next) {
+debug(0,0)("clientHttpConnectionsOpen: port=%d\n", (int) u->i);
+        enter_suid();
+        fd = comm_open(SOCK_STREAM,
+            0,
+            Config.Addrs.tcp_incoming,
+            u->i,
+            COMM_NONBLOCKING,
+            "HTTP Socket");
+        leave_suid();
+        if (fd < 0)
+            continue;
+        comm_listen(fd);
+        commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0);
+        commSetDefer(fd, httpAcceptDefer, NULL);
+        debug(1, 1) ("Accepting HTTP connections on port %d, FD %d.\n",
+            (int) u->i, fd);
+        HttpSockets[NHttpSockets++] = fd;
+    }
+    if (NHttpSockets < 1)
+        fatal("Cannot open HTTP Port");
+}
index 9a93f8462eb6df0a76749e0ffb2ac3241560301d..bf2dee71fcc74cb53e604995fe22ff8d94d54e61 100644 (file)
@@ -429,3 +429,69 @@ icpHandleUdp(int sock, void *datanotused)
            inet_ntoa(from.sin_addr),
            ntohs(from.sin_port));
 }
+
+void
+icpConnectionsOpen(void)
+{
+    u_short port;
+    struct in_addr addr;
+    struct sockaddr_in xaddr;
+    int x;
+    int len;
+    wordlist *s;
+    if (Config2.Accel.on && !Config.onoff.accel_with_proxy)
+       return;
+    if ((port = Config.Port.icp) <= 0)
+       return;
+    enter_suid();
+    theInIcpConnection = comm_open(SOCK_DGRAM,
+       0,
+       Config.Addrs.udp_incoming,
+       port,
+       COMM_NONBLOCKING,
+       "ICP Port");
+    leave_suid();
+    if (theInIcpConnection < 0)
+       fatal("Cannot open ICP Port");
+    fd_note(theInIcpConnection, "ICP socket");
+    commSetSelect(theInIcpConnection,
+       COMM_SELECT_READ,
+       icpHandleUdp,
+       NULL, 0);
+    for (s = Config.mcast_group_list; s; s = s->next)
+       ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
+    debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n",
+       (int) port, theInIcpConnection);
+    if ((addr = Config.Addrs.udp_outgoing).s_addr != no_addr.s_addr) {
+       enter_suid();
+       theOutIcpConnection = comm_open(SOCK_DGRAM,
+           0,
+           addr,
+           port,
+           COMM_NONBLOCKING,
+           "ICP Port");
+       leave_suid();
+       if (theOutIcpConnection < 0)
+           fatal("Cannot open Outgoing ICP Port");
+       commSetSelect(theOutIcpConnection,
+           COMM_SELECT_READ,
+           icpHandleUdp,
+           NULL, 0);
+       debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n",
+           (int) port, theInIcpConnection);
+       fd_note(theOutIcpConnection, "Outgoing ICP socket");
+       fd_note(theInIcpConnection, "Incoming ICP socket");
+    } else {
+       theOutIcpConnection = theInIcpConnection;
+    }
+    memset(&theOutICPAddr, '\0', sizeof(struct in_addr));
+    len = sizeof(struct sockaddr_in);
+    memset(&xaddr, '\0', len);
+    x = getsockname(theOutIcpConnection,
+       (struct sockaddr *) &xaddr, &len);
+    if (x < 0)
+       debug(50, 1) ("theOutIcpConnection FD %d: getsockname: %s\n",
+           theOutIcpConnection, xstrerror());
+    else
+       theOutICPAddr = xaddr.sin_addr;
+}
index 40456711696ec991d1f7323a7745215f268c081e..956efcacbf8200043555923858fd9c530080c7df 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: main.cc,v 1.195 1997/11/21 05:55:53 wessels Exp $
+ * $Id: main.cc,v 1.196 1997/11/23 06:50:26 wessels Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -135,7 +135,7 @@ usage(void)
 {
     fprintf(stderr,
        "Usage: %s [-svzCDFRUVY] [-f config-file] [-[au] port] [-k signal]\n"
-       "       -a port   Specify ASCII port number (default: %d).\n"
+       "       -a port   Specify HTTP port number (default: %d).\n"
        "       -d        Write debugging to stderr also.\n"
        "       -f file   Use given config-file instead of\n"
        "                 %s\n"
@@ -315,94 +315,11 @@ shut_down(int sig)
 static void
 serverConnectionsOpen(void)
 {
-    struct in_addr addr;
-    struct sockaddr_in xaddr;
-    u_short port;
-    ushortlist *u;
-    int len;
-    int x;
-    int fd;
-    wordlist *s;
-    for (u = Config.Port.http; u; u = u->next) {
-       enter_suid();
-       fd = comm_open(SOCK_STREAM,
-           0,
-           Config.Addrs.tcp_incoming,
-           u->i,
-           COMM_NONBLOCKING,
-           "HTTP Socket");
-       leave_suid();
-       if (fd < 0)
-           continue;
-       comm_listen(fd);
-       commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0);
-       commSetDefer(fd, httpAcceptDefer, NULL);
-       debug(1, 1) ("Accepting HTTP connections on port %d, FD %d.\n",
-           (int) u->i, fd);
-       HttpSockets[NHttpSockets++] = fd;
-    }
-    if (NHttpSockets < 1)
-       fatal("Cannot open HTTP Port");
-    if (!Config2.Accel.on || Config.onoff.accel_with_proxy) {
-       if ((port = Config.Port.icp) > (u_short) 0) {
-           enter_suid();
-           theInIcpConnection = comm_open(SOCK_DGRAM,
-               0,
-               Config.Addrs.udp_incoming,
-               port,
-               COMM_NONBLOCKING,
-               "ICP Port");
-           leave_suid();
-           if (theInIcpConnection < 0)
-               fatal("Cannot open ICP Port");
-           fd_note(theInIcpConnection, "ICP socket");
-           commSetSelect(theInIcpConnection,
-               COMM_SELECT_READ,
-               icpHandleUdp,
-               NULL, 0);
-           for (s = Config.mcast_group_list; s; s = s->next)
-               ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
-           debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n",
-               (int) port, theInIcpConnection);
-
-           if ((addr = Config.Addrs.udp_outgoing).s_addr != no_addr.s_addr) {
-               enter_suid();
-               theOutIcpConnection = comm_open(SOCK_DGRAM,
-                   0,
-                   addr,
-                   port,
-                   COMM_NONBLOCKING,
-                   "ICP Port");
-               leave_suid();
-               if (theOutIcpConnection < 0)
-                   fatal("Cannot open Outgoing ICP Port");
-               commSetSelect(theOutIcpConnection,
-                   COMM_SELECT_READ,
-                   icpHandleUdp,
-                   NULL, 0);
-               debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n",
-                   (int) port, theInIcpConnection);
-               fd_note(theOutIcpConnection, "Outgoing ICP socket");
-               fd_note(theInIcpConnection, "Incoming ICP socket");
-           } else {
-               theOutIcpConnection = theInIcpConnection;
-           }
-           memset(&theOutICPAddr, '\0', sizeof(struct in_addr));
-           len = sizeof(struct sockaddr_in);
-           memset(&xaddr, '\0', len);
-           x = getsockname(theOutIcpConnection,
-               (struct sockaddr *) &xaddr, &len);
-           if (x < 0)
-               debug(50, 1) ("theOutIcpConnection FD %d: getsockname: %s\n",
-                   theOutIcpConnection, xstrerror());
-           else
-               theOutICPAddr = xaddr.sin_addr;
-       }
-    }
+    clientHttpConnectionsOpen();
+    icpConnectionsOpen();
 #ifdef SQUID_SNMP
     snmpConnectionOpen();
 #endif
-
     clientdbInit();
     icmpOpen();
     netdbInit();
@@ -440,6 +357,9 @@ serverConnectionsClose(void)
     }
     if (icmp_sock > -1)
        icmpClose();
+#ifdef SQUID_SNMP
+    snmpConnectionClose();
+#endif
 }
 
 static void
@@ -447,6 +367,13 @@ mainReconfigure(void)
 {
     debug(1, 0) ("Restarting Squid Cache (version %s)...\n", version_string);
     /* Already called serverConnectionsClose and ipcacheShutdownServers() */
+    serverConnectionsClose();
+    if (theOutIcpConnection > 0) {
+       comm_close(theOutIcpConnection);
+       theOutIcpConnection = -1;
+    }
+    dnsShutdownServers();
+    redirectShutdownServers();
     storeDirCloseSwapLogs();
     parseConfigFile(ConfigFile);
     _db_init(Config.Log.log, Config.debugOptions);
@@ -638,7 +565,10 @@ main(int argc, char **argv)
 
     /* main loop */
     for (;;) {
-       if (rotate_pending) {
+       if (reconfigure_pending) {
+               mainReconfigure();
+               reconfigure_pending = 0;        /* reset */
+       } else if (rotate_pending) {
            icmpClose();
            _db_rotate_log();   /* cache.log */
            storeWriteCleanLogs(1);
@@ -673,9 +603,11 @@ main(int argc, char **argv)
            }
            if (shutdown_pending) {
                normal_shutdown();
+#if 0
            } else if (reconfigure_pending) {
                mainReconfigure();
                reconfigure_pending = 0;        /* reset */
+#endif
            } else {
                fatal_dump("MAIN: SHUTDOWN from comm_select, but nothing pending.");
            }