From: wessels <> Date: Wed, 7 Jan 1998 01:12:22 +0000 (+0000) Subject: Fixed up 'fooConnectionsClose()' functions. created icpConnectionsClose() X-Git-Tag: SQUID_3_0_PRE1~4239 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0fbae1678c6473964ca796810d4289112158f14;p=thirdparty%2Fsquid.git Fixed up 'fooConnectionsClose()' functions. created icpConnectionsClose() and clientHttpConnectionsClose(). For the UDP sockets, fixed a bug which caused us to try closing the same FD twice. --- diff --git a/src/client_side.cc b/src/client_side.cc index e347ecbc16..25bc2e889f 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.192 1998/01/06 05:15:39 wessels Exp $ + * $Id: client_side.cc,v 1.193 1998/01/06 18:12:22 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1993,3 +1993,17 @@ clientHttpConnectionsOpen(void) if (NHttpSockets < 1) fatal("Cannot open HTTP Port"); } + +void +clientHttpConnectionsClose(void) +{ + int i; + for (i = 0; i < NHttpSockets; i++) { + if (HttpSockets[i] >= 0) { + debug(1, 1) ("FD %d Closing HTTP connection\n", HttpSockets[i]); + comm_close(HttpSockets[i]); + HttpSockets[i] = -1; + } + } + NHttpSockets = 0; +} diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 426d3c784e..96a3911164 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -495,3 +495,28 @@ icpConnectionsOpen(void) else theOutICPAddr = xaddr.sin_addr; } + +void +icpConnectionsClose(void) +{ + if (theInIcpConnection < 0) + return; + debug(1, 1) ("FD %d Closing ICP connection\n", theInIcpConnection); + if (theInIcpConnection != theOutIcpConnection) + comm_close(theInIcpConnection); + /* + * Here we set 'theInIcpConnection' to -1 even though the ICP 'in' + * and 'out' sockets might be just one FD. This prevents this + * function from executing repeatedly. When we are really ready to + * exit or restart, main will comm_close the 'out' descriptor. + */ + theInIcpConnection = -1; + /* + * Normally we only write to the outgoing ICP socket, but + * we also have a read handler there to catch messages sent + * to that specific interface. During shutdown, we must + * disable reading on the outgoing socket. + */ + assert(theOutIcpConnection > -1); + commSetSelect(theOutIcpConnection, COMM_SELECT_READ, NULL, NULL, 0); +} diff --git a/src/main.cc b/src/main.cc index 3ce3c357a4..56a77c0f5f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.203 1998/01/06 07:11:53 wessels Exp $ + * $Id: main.cc,v 1.204 1998/01/06 18:12:23 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -337,47 +337,9 @@ serverConnectionsClose(void) * NOTE, this function will be called repeatedly while shutdown * is pending */ - int i; - for (i = 0; i < NHttpSockets; i++) { - if (HttpSockets[i] >= 0) { - debug(1, 1) ("FD %d Closing HTTP connection\n", HttpSockets[i]); - comm_close(HttpSockets[i]); - HttpSockets[i] = -1; - } - } - NHttpSockets = 0; - if (theInIcpConnection > -1) { - /* - * NOTE, don't close outgoing ICP connection, we need to write - * to it during shutdown. - */ - debug(1, 1) ("FD %d Closing ICP connection\n", - theInIcpConnection); - if (theInIcpConnection != theOutIcpConnection) { - comm_close(theInIcpConnection); - assert(theOutIcpConnection > -1); - /* - * Normally we only write to the outgoing ICP socket, but - * we also have a read handler there to catch messages sent - * to that specific interface. During shutdown, we must - * disable reading on the outgoing socket. - */ - commSetSelect(theOutIcpConnection, - COMM_SELECT_READ, - NULL, - NULL, - 0); - } else { - commSetSelect(theInIcpConnection, - COMM_SELECT_READ, - NULL, - NULL, - 0); - } - theInIcpConnection = -1; - } - if (icmp_sock > -1) - icmpClose(); + clientHttpConnectionsClose(); + icpConnectionsClose(); + icmpClose(); #ifdef SQUID_SNMP snmpConnectionClose(); #endif diff --git a/src/protos.h b/src/protos.h index abfefe6399..bd7c84549d 100644 --- a/src/protos.h +++ b/src/protos.h @@ -77,6 +77,7 @@ extern char *clientConstructTraceEcho(clientHttpRequest *); extern void clientPurgeRequest(clientHttpRequest *); extern int checkNegativeHit(StoreEntry *); extern void clientHttpConnectionsOpen(void); +extern void clientHttpConnectionsClose(void); extern StoreEntry *clientCreateStoreEntry(clientHttpRequest *, method_t, int); extern int commSetNonBlocking(int fd); @@ -267,6 +268,7 @@ extern int icpCheckUdpHitObj(StoreEntry * e, request_t * r, icp_common_t * h, in extern void *icpCreateHitObjMessage(icp_opcode, int, const char *, int, int, StoreEntry *); #endif extern void icpConnectionsOpen(void); +extern void icpConnectionsClose(void); extern void ipcache_nbgethostbyname(const char *name, IPH * handler,