/*
- * $Id: comm.cc,v 1.159 1997/06/04 06:15:48 wessels Exp $
+ * $Id: comm.cc,v 1.160 1997/06/04 07:00:31 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
* 64 file descriptors free for disk-i/o and connections to remote servers */
int RESERVED_FD = 64;
+int polledinc = 0;
#define min(x,y) ((x)<(y)? (x) : (y))
#define max(a,b) ((a)>(b)? (a) : (b))
unsigned long i, nfds;
int j;
PF *hdl = NULL;
+ polledinc = 0;
if (theInIcpConnection >= 0)
fds[N++] = theInIcpConnection;
if (theInIcpConnection != theOutIcpConnection)
}
if (!nfds)
return;
- if (poll(pfds, nfds, 0) < 1)
+ polledinc = poll(pfds, nfds, 0);
+ if (polledinc < 1) {
+ polledinc = 0;
return;
-#ifndef LESS_TIMING
- getCurrentTime();
-#endif
+ }
for (i = 0; i < nfds; i++) {
int revents;
if (((revents = pfds[i].revents) == 0) || ((fd = pfds[i].fd) == -1))
int N = 0;
int i = 0;
PF *hdl = NULL;
+ polledinc = 0;
FD_ZERO(&read_mask);
FD_ZERO(&write_mask);
for (i = 0; i < NHttpSockets; i++) {
}
if (maxfd++ == 0)
return;
- if (select(maxfd, &read_mask, &write_mask, NULL, &zero_tv) < 1)
+ polledinc = select(maxfd, &read_mask, &write_mask, NULL, &zero_tv);
+ if (polledinc < 1) {
+ polledinc = 0;
return;
-#ifndef LESS_TIMING
- getCurrentTime();
-#endif
+ }
for (i = 0; i < N; i++) {
fd = fds[i];
if (FD_ISSET(fd, &read_mask)) {
unsigned long nfds;
int num;
static time_t last_timeout = 0;
+ static int lastinc = 0;
int poll_time;
static int incoming_counter = 0;
time_t timeout;
/* assume all process are very fast (less than 1 second). Call
* time() only once */
- getCurrentTime();
/* use only 1 second granularity */
timeout = squid_curtime + sec;
do {
- if (sec > 60)
- fatal_dump(NULL);
if (shutdown_pending || reconfigure_pending) {
serverConnectionsClose();
dnsShutdownServers();
poll_time = sec > 0 ? 1000 : 0;
num = poll(pfds, nfds, poll_time);
select_loops++;
- getCurrentTime();
if (num >= 0)
break;
if (errno == EINTR)
return COMM_ERROR;
/* NOTREACHED */
}
- getCurrentTime();
debug(5, num ? 5 : 8) ("comm_poll: %d sockets ready\n", num);
/* Check timeout handlers ONCE each second. */
if (squid_curtime > last_timeout) {
int revents;
if (((revents = pfds[i].revents) == 0) || ((fd = pfds[i].fd) == -1))
continue;
- if ((incoming_counter++ % 2) == 0)
+ if ((incoming_counter++ & (lastinc > 0 ? 1 : 7)) == 0)
comm_poll_incoming();
if (fdIsHttpOrIcp(fd))
continue;
fde->read_handler = NULL;
fde->write_handler = NULL;
}
+ lastinc = polledinc;
}
return COMM_OK;
- } while (timeout > getCurrentTime());
+ } while (timeout > squid_curtime);
debug(5, 8) ("comm_poll: time out: %d.\n", squid_curtime);
return COMM_TIMEOUT;
}
int maxfd;
int nfds;
int num;
+ static int incoming_counter = 0;
static time_t last_timeout = 0;
struct timeval poll_time;
+ static int lastinc;
time_t timeout;
/* assume all process are very fast (less than 1 second). Call
* time() only once */
- getCurrentTime();
/* use only 1 second granularity */
timeout = squid_curtime + sec;
do {
- if (sec > 60)
- fatal_dump(NULL);
FD_ZERO(&readfds);
FD_ZERO(&writefds);
-
if (shutdown_pending || reconfigure_pending) {
serverConnectionsClose();
dnsShutdownServers();
poll_time.tv_usec = 0;
num = select(maxfd, &readfds, &writefds, NULL, &poll_time);
select_loops++;
- getCurrentTime();
if (num >= 0)
break;
if (errno == EINTR)
for (fd = 0; fd < maxfd; fd++) {
if (!FD_ISSET(fd, &readfds) && !FD_ISSET(fd, &writefds))
continue;
- /*
- * Admit more connections quickly until we hit the hard limit.
- * Don't forget to keep the UDP acks coming and going.
- */
- comm_select_incoming();
-
+ if ((incoming_counter++ & (lastinc > 0 ? 1 : 7) == 0)
+ comm_poll_incoming();
if (fdIsHttpOrIcp(fd))
continue;
if (FD_ISSET(fd, &readfds)) {
hdl = fd_table[fd].read_handler;
fd_table[fd].read_handler = 0;
hdl(fd, fd_table[fd].read_data);
- comm_select_incoming();
}
}
if (FD_ISSET(fd, &writefds)) {
hdl = fd_table[fd].write_handler;
fd_table[fd].write_handler = 0;
hdl(fd, fd_table[fd].write_data);
- comm_select_incoming();
}
}
+ lastinc = polledinc;
}
return COMM_OK;
- } while (timeout > getCurrentTime());
-
+ } while (timeout > squid_curtime);
debug(5, 8) ("comm_select: time out: %d.\n", squid_curtime);
return COMM_TIMEOUT;
}
/*
- * $Id: main.cc,v 1.151 1997/06/04 06:16:01 wessels Exp $
+ * $Id: main.cc,v 1.152 1997/06/04 07:00:31 wessels Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
static void rotate_logs _PARAMS((int));
static void reconfigure _PARAMS((int));
+static void time_tick _PARAMS((int));
static void mainInitialize _PARAMS((void));
static void mainReconfigure _PARAMS((void));
static void usage _PARAMS((void));
#endif
}
+static void
+time_tick(int sig)
+{
+ getCurrentTime();
+ alarm(1);
+#if !HAVE_SIGACTION
+ signal(sig, time_tick);
+#endif
+}
+
+
static void
reconfigure(int sig)
{
squid_signal(SIGHUP, reconfigure, SA_RESTART);
squid_signal(SIGTERM, shut_down, SA_NODEFER | SA_RESETHAND | SA_RESTART);
squid_signal(SIGINT, shut_down, SA_NODEFER | SA_RESETHAND | SA_RESTART);
+ squid_signal(SIGALRM, time_tick, SA_RESTART);
+ alarm(1);
debug(1, 0) ("Ready to serve requests.\n");
if (!configured_once) {
/*
- * $Id: store.cc,v 1.252 1997/06/04 06:16:11 wessels Exp $
+ * $Id: store.cc,v 1.253 1997/06/04 07:00:34 wessels Exp $
*
* DEBUG: section 20 Storeage Manager
* AUTHOR: Harvest Derived
{
time_t r;
time_t stop;
- stop = getCurrentTime();
+ stop = squid_curtime;
r = stop - data->start;
debug(20, 1) ("Finished rebuilding storage from disk image.\n");
debug(20, 1) (" %7d Lines read from previous logfile.\n", data->linecount);
eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate);
for (e = storeGetFirst(); e; e = storeGetNext()) {
if ((++n & 0xFF) == 0) {
- getCurrentTime();
if (shutdown_pending || reconfigure_pending)
break;
}
} else {
swap_help = 0;
}
-
- getCurrentTime(); /* we may have taken more than one second */
debug(20, 2) ("Removed %d objects\n", removed);
return 0;
}
return 0;
}
debug(20, 1) ("storeWriteCleanLogs: Starting...\n");
- start = getCurrentTime();
+ start = squid_curtime;
fd = xcalloc(ncache_dirs, sizeof(int));
cur = xcalloc(ncache_dirs, sizeof(char *));
new = xcalloc(ncache_dirs, sizeof(char *));
continue;
}
if ((++n & 0x3FFF) == 0) {
- getCurrentTime();
debug(20, 1) (" %7d lines written so far.\n", n);
}
}
}
storeDirCloseSwapLogs();
storeDirOpenSwapLogs();
- stop = getCurrentTime();
+ stop = squid_curtime;
r = stop - start;
debug(20, 1) (" Finished. Wrote %d lines.\n", n);
debug(20, 1) (" Took %d seconds (%6.1lf lines/sec).\n",