Index: acconfig.h
===================================================================
RCS file: /server/cvs-server/squid/squid/acconfig.h,v
retrieving revision 1.61
diff -u -a -r1.61 acconfig.h
--- acconfig.h	2001/11/28 08:01:41	1.61
+++ acconfig.h	2001/12/21 06:03:35
@@ -351,6 +351,10 @@
  */
 #undef X_ACCELERATOR_VARY
 
+/* Support for poll/select/etc stuff */
+#undef USE_POLL
+#undef USE_SELECT
+
 @BOTTOM@
 
 #endif /* __CONFIGURE_H__ */
+#line 7626 "configure"
 #include "confdefs.h"
 
 #if HAVE_SYS_TYPES_H
Index: configure.in
===================================================================
RCS file: /server/cvs-server/squid/squid/configure.in,v
retrieving revision 1.251
diff -u -a -r1.251 configure.in
--- configure.in	2001/11/30 16:06:32	1.251
+++ configure.in	2001/12/21 06:03:36
@@ -1,4 +1,4 @@
-dnl
+
 dnl  Configuration input file for Squid
 dnl
 dnl  Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9)
@@ -658,15 +658,13 @@
    fi
 ])
 
+dnl check for netio plugin stuff
 dnl Enable poll()
 AC_ARG_ENABLE(poll,
-[  --enable-poll           Enable poll() instead of select().  Normally poll
-                          is preferred over select, but configure knows poll
-                          is broken on some platforms.  If you think you are
-                          smarter than the configure script, you may enable
-                          poll with this option.
-  --disable-poll          Disable the use of poll().],
-[ 
+[ --enable-poll         Enable poll() support.
+  --disable-poll        Disable poll() support. ],
+
+[
   case "$enableval" in
   yes)
     echo "Forcing poll() to be enabled"
@@ -679,6 +677,42 @@
   esac
 ])
 
+dnl Enable select()
+AC_ARG_ENABLE(select,
+[ --enable-select       Enable select() support.
+  --disable-select      Disable select() support. ],
+
+[
+  case "$enableval" in
+  yes)
+    echo "Forcing select() to be enabled"
+    ac_cv_func_select='yes'
+    ;;
+  no)
+    echo "Forcing select() to be disabled"
+    ac_cv_func_select='no'
+    ;;
+  esac
+])
+
+dnl Enable kqueue()
+AC_ARG_ENABLE(kqueue,
+[ --enable-kqueue       Enable kqueue() support.
+  --disable-kqueue      Disable kqueue() support. ],
+
+[
+  case "$enableval" in
+  yes)
+    echo "Forcing kqueue() to be enabled"
+    ac_cv_func_kqueue='yes'
+    ;;
+  no)
+    echo "Forcing kqueue() to be disabled"
+    ac_cv_func_kqueue='no'
+  ;;
+esac
+])
+
 dnl Disable HTTP violations
 AC_ARG_ENABLE(http-violations,
 [  --disable-http-violations
@@ -1565,6 +1599,28 @@
 	bswap_16 \
 	bswap_32 \
 )
+
+dnl Magic which checks whether we are forcing a type of comm loop we
+dnl are actually going to (ab)use
+ 
+dnl Actually do the define magic now
+dnl mostly ripped from squid-commloops, thanks to adrian and benno
+
+if test "$ac_cv_func_poll" = "yes" ; then
+        SELECT_TYPE="poll"
+        AC_DEFINE(USE_POLL)
+elif test "$ac_cv_func_select" = "yes" ; then
+        SELECT_TYPE="select"
+        AC_DEFINE(USE_SELECT)
+else
+        echo "Eep!  Can't find poll or select!"
+        echo "I'll try select and hope for the best."
+        SELECT_TYPE="select"
+        AC_DEFINE(USE_SELECT)
+fi
+echo "Using ${SELECT_TYPE} for select loop."
+AC_DEFINE_UNQUOTED(SELECT_TYPE, "$SELECT_TYPE")
+
 
 dnl Yay!  Another Linux brokenness.  Its not good enough
 dnl to know that setresuid() exists, because RedHat 5.0 declares
Index: include/autoconf.h.in
===================================================================
RCS file: /server/cvs-server/squid/squid/include/autoconf.h.in,v
retrieving revision 1.109
diff -u -a -r1.109 autoconf.h.in
--- include/autoconf.h.in	2001/11/29 11:16:52	1.109
+++ include/autoconf.h.in	2001/12/21 06:03:36
@@ -52,6 +52,15 @@
 /* Define to `int' if <sys/types.h> doesn't define.  */
 #undef pid_t
 
+/* Define to the type of arg1 for select(). */
+#undef SELECT_TYPE_ARG1
+
+/* Define to the type of args 2, 3 and 4 for select(). */
+#undef SELECT_TYPE_ARG234
+
+/* Define to the type of arg5 for select(). */
+#undef SELECT_TYPE_ARG5
+
 /* Define to `unsigned' if <sys/types.h> doesn't define.  */
 #undef size_t
 
@@ -383,6 +392,10 @@
  * Enable support for the X-Accelerator-Vary HTTP header
  */
 #undef X_ACCELERATOR_VARY
+
+/* Support for poll/select/etc stuff */
+#undef USE_POLL
+#undef USE_SELECT
 
 /* The number of bytes in a __int64.  */
 #undef SIZEOF___INT64
 SHELL = @SHELL@
Index: src/Makefile.am
===================================================================
RCS file: /server/cvs-server/squid/squid/src/Makefile.am,v
retrieving revision 1.16
diff -u -a -r1.16 Makefile.am
--- src/Makefile.am	2001/11/30 16:22:35	1.16
+++ src/Makefile.am	2001/12/21 06:03:36
@@ -112,6 +112,7 @@
 	client_side.c \
 	comm.c \
 	comm_select.c \
+	comm_poll.c \
 	debug.c \
 	defines.h \
 	$(DELAY_POOL_SOURCE) \
Index: src/comm.c
===================================================================
RCS file: /server/cvs-server/squid/squid/src/comm.c,v
retrieving revision 1.324
diff -u -a -r1.324 comm.c
--- src/comm.c	2001/10/24 07:45:34	1.324
+++ src/comm.c	2001/12/21 06:03:36
@@ -684,27 +684,6 @@
 }
 
 void
-commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout)
-{
-    fde *F = &fd_table[fd];
-    assert(fd >= 0);
-    assert(F->flags.open);
-    debug(5, 5) ("commSetSelect: FD %d type %d\n", fd, type);
-    if (type & COMM_SELECT_READ) {
-	F->read_handler = handler;
-	F->read_data = client_data;
-	commUpdateReadBits(fd, handler);
-    }
-    if (type & COMM_SELECT_WRITE) {
-	F->write_handler = handler;
-	F->write_data = client_data;
-	commUpdateWriteBits(fd, handler);
-    }
-    if (timeout)
-	F->timeout = squid_curtime + timeout;
-}
-
-void
 comm_add_close_handler(int fd, PF * handler, void *data)
 {
     close_handler *new = memPoolAlloc(conn_close_pool);		/* AAA */
@@ -999,3 +978,41 @@
 	}
     }
 }
+
+void
+checkTimeouts(void)
+{
+    int fd;
+    fde *F = NULL;
+    PF *callback;
+    for (fd = 0; fd <= Biggest_FD; fd++) {
+        F = &fd_table[fd];
+        if (!F->flags.open)
+            continue;
+        if (F->timeout == 0)
+            continue;
+        if (F->timeout > squid_curtime)
+            continue;
+        debug(5, 5) ("checkTimeouts: FD %d Expired\n", fd);
+        if (F->timeout_handler) {
+            debug(5, 5) ("checkTimeouts: FD %d: Call timeout handler\n", fd);
+            callback = F->timeout_handler;
+            F->timeout_handler = NULL;
+            callback(fd, F->timeout_data);
+        } else {
+            debug(5, 5) ("checkTimeouts: FD %d: Forcing comm_close()\n", fd);
+            comm_close(fd);
+        }
+    }
+}
+
+
+int 
+commDeferRead(int fd)
+{
+    fde *F = &fd_table[fd];
+    if (F->defer_check == NULL)
+        return 0;
+    return F->defer_check(fd, F->defer_data);
+}
+
Index: src/comm_select.c
===================================================================
RCS file: /server/cvs-server/squid/squid/src/comm_select.c,v
retrieving revision 1.53
diff -u -a -r1.53 comm_select.c
--- src/comm_select.c	2001/10/24 06:55:44	1.53
+++ src/comm_select.c	2001/12/21 06:03:37
@@ -34,6 +34,8 @@
 
 #include "squid.h"
 
+#ifdef USE_SELECT
+
 static int MAX_POLL_TIME = 1000;	/* see also comm_quick_poll_required() */
 
 #ifndef        howmany
@@ -46,26 +48,18 @@
 #define FD_MASK_BITS (FD_MASK_BYTES*NBBY)
 
 /* STATIC */
-#if !HAVE_POLL
 static int examine_select(fd_set *, fd_set *);
-#endif
 static int fdIsHttp(int fd);
 static int fdIsIcp(int fd);
 static int fdIsDns(int fd);
-static int commDeferRead(int fd);
-static void checkTimeouts(void);
 static OBJH commIncomingStats;
-#if HAVE_POLL
-static int comm_check_incoming_poll_handlers(int nfds, int *fds);
-static void comm_poll_dns_incoming(void);
-#else
 static int comm_check_incoming_select_handlers(int nfds, int *fds);
 static void comm_select_dns_incoming(void);
-#endif
+static void commUpdateReadBits(int fd, PF * handler);
+static void commUpdateWriteBits(int fd, PF * handler);
 
-#if !HAVE_POLL
+
 static struct timeval zero_tv;
-#endif
 static fd_set global_readfds;
 static fd_set global_writefds;
 static int nreadfds;
@@ -132,15 +126,29 @@
 #define commCheckDNSIncoming (++dns_io_events > (incoming_dns_interval>> INCOMING_FACTOR))
 #define commCheckHTTPIncoming (++http_io_events > (incoming_http_interval>> INCOMING_FACTOR))
 
-static int
-commDeferRead(int fd)
+void
+commSetSelect(int fd, unsigned int type, PF * handler, void *client_data,
+  time_t timeout)
 {
     fde *F = &fd_table[fd];
-    if (F->defer_check == NULL)
-	return 0;
-    return F->defer_check(fd, F->defer_data);
+    assert(fd >= 0);
+    assert(F->flags.open);
+    debug(5, 5) ("commSetSelect: FD %d type %d\n", fd, type);
+    if (type & COMM_SELECT_READ) {
+        F->read_handler = handler;
+        F->read_data = client_data;
+        commUpdateReadBits(fd, handler);
+    }
+    if (type & COMM_SELECT_WRITE) {
+        F->write_handler = handler;
+        F->write_data = client_data;
+        commUpdateWriteBits(fd, handler);
+    }
+    if (timeout)
+        F->timeout = squid_curtime + timeout;
 }
 
+
 static int
 fdIsIcp(int fd)
 {
@@ -195,337 +203,6 @@
 }
 #endif
 
-#if HAVE_POLL
-static int
-comm_check_incoming_poll_handlers(int nfds, int *fds)
-{
-    int i;
-    int fd;
-    PF *hdl = NULL;
-    int npfds;
-    struct pollfd pfds[3 + MAXHTTPPORTS];
-    incoming_sockets_accepted = 0;
-    for (i = npfds = 0; i < nfds; i++) {
-	int events;
-	fd = fds[i];
-	events = 0;
-	if (fd_table[fd].read_handler)
-	    events |= POLLRDNORM;
-	if (fd_table[fd].write_handler)
-	    events |= POLLWRNORM;
-	if (events) {
-	    pfds[npfds].fd = fd;
-	    pfds[npfds].events = events;
-	    pfds[npfds].revents = 0;
-	    npfds++;
-	}
-    }
-    if (!nfds)
-	return -1;
-#if !ALARM_UPDATES_TIME
-    getCurrentTime();
-#endif
-    statCounter.syscalls.polls++;
-    if (poll(pfds, npfds, 0) < 1)
-	return incoming_sockets_accepted;
-    for (i = 0; i < npfds; i++) {
-	int revents;
-	if (((revents = pfds[i].revents) == 0) || ((fd = pfds[i].fd) == -1))
-	    continue;
-	if (revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
-	    if ((hdl = fd_table[fd].read_handler)) {
-		fd_table[fd].read_handler = NULL;
-		hdl(fd, fd_table[fd].read_data);
-	    } else if (pfds[i].events & POLLRDNORM)
-		debug(5, 1) ("comm_poll_incoming: FD %d NULL read handler\n",
-		    fd);
-	}
-	if (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) {
-	    if ((hdl = fd_table[fd].write_handler)) {
-		fd_table[fd].write_handler = NULL;
-		hdl(fd, fd_table[fd].write_data);
-	    } else if (pfds[i].events & POLLWRNORM)
-		debug(5, 1) ("comm_poll_incoming: FD %d NULL write_handler\n",
-		    fd);
-	}
-    }
-    return incoming_sockets_accepted;
-}
-
-static void
-comm_poll_icp_incoming(void)
-{
-    int nfds = 0;
-    int fds[2];
-    int nevents;
-    icp_io_events = 0;
-    if (theInIcpConnection >= 0)
-	fds[nfds++] = theInIcpConnection;
-    if (theInIcpConnection != theOutIcpConnection)
-	if (theOutIcpConnection >= 0)
-	    fds[nfds++] = theOutIcpConnection;
-    if (nfds == 0)
-	return;
-    nevents = comm_check_incoming_poll_handlers(nfds, fds);
-    incoming_icp_interval += Config.comm_incoming.icp_average - nevents;
-    if (incoming_icp_interval < Config.comm_incoming.icp_min_poll)
-	incoming_icp_interval = Config.comm_incoming.icp_min_poll;
-    if (incoming_icp_interval > MAX_INCOMING_INTERVAL)
-	incoming_icp_interval = MAX_INCOMING_INTERVAL;
-    if (nevents > INCOMING_ICP_MAX)
-	nevents = INCOMING_ICP_MAX;
-    statHistCount(&statCounter.comm_icp_incoming, nevents);
-}
-
-static void
-comm_poll_http_incoming(void)
-{
-    int nfds = 0;
-    int fds[MAXHTTPPORTS];
-    int j;
-    int nevents;
-    http_io_events = 0;
-    for (j = 0; j < NHttpSockets; j++) {
-	if (HttpSockets[j] < 0)
-	    continue;
-	if (commDeferRead(HttpSockets[j]))
-	    continue;
-	fds[nfds++] = HttpSockets[j];
-    }
-    nevents = comm_check_incoming_poll_handlers(nfds, fds);
-    incoming_http_interval = incoming_http_interval
-	+ Config.comm_incoming.http_average - nevents;
-    if (incoming_http_interval < Config.comm_incoming.http_min_poll)
-	incoming_http_interval = Config.comm_incoming.http_min_poll;
-    if (incoming_http_interval > MAX_INCOMING_INTERVAL)
-	incoming_http_interval = MAX_INCOMING_INTERVAL;
-    if (nevents > INCOMING_HTTP_MAX)
-	nevents = INCOMING_HTTP_MAX;
-    statHistCount(&statCounter.comm_http_incoming, nevents);
-}
-
-/* poll all sockets; call handlers for those that are ready. */
-int
-comm_poll(int msec)
-{
-    struct pollfd pfds[SQUID_MAXFD];
-#if DELAY_POOLS
-    fd_set slowfds;
-#endif
-    PF *hdl = NULL;
-    int fd;
-    int i;
-    int maxfd;
-    unsigned long nfds;
-    unsigned long npending;
-    int num;
-    int callicp = 0, callhttp = 0;
-    int calldns = 0;
-    static time_t last_timeout = 0;
-    double timeout = current_dtime + (msec / 1000.0);
-    do {
-#if !ALARM_UPDATES_TIME
-	double start;
-	getCurrentTime();
-	start = current_dtime;
-#endif
-	/* Handle any fs callbacks that need doing */
-	storeDirCallback();
-#if DELAY_POOLS
-	FD_ZERO(&slowfds);
-#endif
-	if (commCheckICPIncoming)
-	    comm_poll_icp_incoming();
-	if (commCheckDNSIncoming)
-	    comm_poll_dns_incoming();
-	if (commCheckHTTPIncoming)
-	    comm_poll_http_incoming();
-	callicp = calldns = callhttp = 0;
-	nfds = 0;
-	npending = 0;
-	maxfd = Biggest_FD + 1;
-	for (i = 0; i < maxfd; i++) {
-	    int events;
-	    events = 0;
-	    /* Check each open socket for a handler. */
-	    if (fd_table[i].read_handler) {
-		switch (commDeferRead(i)) {
-		case 0:
-		    events |= POLLRDNORM;
-		    break;
-		case 1:
-		    break;
-#if DELAY_POOLS
-		case -1:
-		    events |= POLLRDNORM;
-		    FD_SET(i, &slowfds);
-		    break;
-#endif
-		default:
-		    fatalf("bad return value from commDeferRead(FD %d)\n", i);
-		}
-	    }
-	    if (fd_table[i].write_handler)
-		events |= POLLWRNORM;
-	    if (events) {
-		pfds[nfds].fd = i;
-		pfds[nfds].events = events;
-		pfds[nfds].revents = 0;
-		nfds++;
-		if ((events & POLLRDNORM) && fd_table[i].flags.read_pending)
-		    npending++;
-	    }
-	}
-	if (nfds == 0) {
-	    assert(shutting_down);
-	    return COMM_SHUTDOWN;
-	}
-	if (npending)
-	    msec = 0;
-	if (msec > MAX_POLL_TIME)
-	    msec = MAX_POLL_TIME;
-	for (;;) {
-	    statCounter.syscalls.polls++;
-	    num = poll(pfds, nfds, msec);
-	    statCounter.select_loops++;
-	    if (num >= 0 || npending >= 0)
-		break;
-	    if (ignoreErrno(errno))
-		continue;
-	    debug(5, 0) ("comm_poll: poll failure: %s\n", xstrerror());
-	    assert(errno != EINVAL);
-	    return COMM_ERROR;
-	    /* NOTREACHED */
-	}
-	debug(5, num ? 5 : 8) ("comm_poll: %d+%ld FDs ready\n", num, npending);
-	statHistCount(&statCounter.select_fds_hist, num);
-	/* Check timeout handlers ONCE each second. */
-	if (squid_curtime > last_timeout) {
-	    last_timeout = squid_curtime;
-	    checkTimeouts();
-	}
-	if (num == 0 && npending == 0)
-	    continue;
-	/* scan each socket but the accept socket. Poll this 
-	 * more frequently to minimize losses due to the 5 connect 
-	 * limit in SunOS */
-	for (i = 0; i < nfds; i++) {
-	    fde *F;
-	    int revents = pfds[i].revents;
-	    fd = pfds[i].fd;
-	    if (fd == -1)
-		continue;
-	    if (fd_table[fd].flags.read_pending)
-		revents |= POLLIN;
-	    if (revents == 0)
-		continue;
-	    if (fdIsIcp(fd)) {
-		callicp = 1;
-		continue;
-	    }
-	    if (fdIsDns(fd)) {
-		calldns = 1;
-		continue;
-	    }
-	    if (fdIsHttp(fd)) {
-		callhttp = 1;
-		continue;
-	    }
-	    F = &fd_table[fd];
-	    if (revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
-		debug(5, 6) ("comm_poll: FD %d ready for reading\n", fd);
-		if (NULL == (hdl = F->read_handler))
-		    (void) 0;
-#if DELAY_POOLS
-		else if (FD_ISSET(fd, &slowfds))
-		    commAddSlowFd(fd);
-#endif
-		else {
-		    F->read_handler = NULL;
-		    hdl(fd, F->read_data);
-		    statCounter.select_fds++;
-		    if (commCheckICPIncoming)
-			comm_poll_icp_incoming();
-		    if (commCheckDNSIncoming)
-			comm_poll_dns_incoming();
-		    if (commCheckHTTPIncoming)
-			comm_poll_http_incoming();
-		}
-	    }
-	    if (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) {
-		debug(5, 5) ("comm_poll: FD %d ready for writing\n", fd);
-		if ((hdl = F->write_handler)) {
-		    F->write_handler = NULL;
-		    hdl(fd, F->write_data);
-		    statCounter.select_fds++;
-		    if (commCheckICPIncoming)
-			comm_poll_icp_incoming();
-		    if (commCheckDNSIncoming)
-			comm_poll_dns_incoming();
-		    if (commCheckHTTPIncoming)
-			comm_poll_http_incoming();
-		}
-	    }
-	    if (revents & POLLNVAL) {
-		close_handler *ch;
-		debug(5, 0) ("WARNING: FD %d has handlers, but it's invalid.\n", fd);
-		debug(5, 0) ("FD %d is a %s\n", fd, fdTypeStr[F->type]);
-		debug(5, 0) ("--> %s\n", F->desc);
-		debug(5, 0) ("tmout:%p read:%p write:%p\n",
-		    F->timeout_handler,
-		    F->read_handler,
-		    F->write_handler);
-		for (ch = F->close_handler; ch; ch = ch->next)
-		    debug(5, 0) (" close handler: %p\n", ch->handler);
-		if (F->close_handler) {
-		    commCallCloseHandlers(fd);
-		} else if (F->timeout_handler) {
-		    debug(5, 0) ("comm_poll: Calling Timeout Handler\n");
-		    F->timeout_handler(fd, F->timeout_data);
-		}
-		F->close_handler = NULL;
-		F->timeout_handler = NULL;
-		F->read_handler = NULL;
-		F->write_handler = NULL;
-		if (F->flags.open)
-		    fd_close(fd);
-	    }
-	}
-	if (callicp)
-	    comm_poll_icp_incoming();
-	if (calldns)
-	    comm_poll_dns_incoming();
-	if (callhttp)
-	    comm_poll_http_incoming();
-#if DELAY_POOLS
-	while ((fd = commGetSlowFd()) != -1) {
-	    fde *F = &fd_table[fd];
-	    debug(5, 6) ("comm_select: slow FD %d selected for reading\n", fd);
-	    if ((hdl = F->read_handler)) {
-		F->read_handler = NULL;
-		hdl(fd, F->read_data);
-		statCounter.select_fds++;
-		if (commCheckICPIncoming)
-		    comm_poll_icp_incoming();
-		if (commCheckDNSIncoming)
-		    comm_poll_dns_incoming();
-		if (commCheckHTTPIncoming)
-		    comm_poll_http_incoming();
-	    }
-	}
-#endif
-#if !ALARM_UPDATES_TIME
-	getCurrentTime();
-	statCounter.select_time += (current_dtime - start);
-#endif
-	return COMM_OK;
-    }
-    while (timeout > current_dtime);
-    debug(5, 8) ("comm_poll: time out: %ld.\n", (long int) squid_curtime);
-    return COMM_TIMEOUT;
-}
-
-#else
 
 static int
 comm_check_incoming_select_handlers(int nfds, int *fds)
@@ -904,14 +581,9 @@
     debug(5, 8) ("comm_select: time out: %d\n", (int) squid_curtime);
     return COMM_TIMEOUT;
 }
-#endif
 
 static void
-#if HAVE_POLL
-comm_poll_dns_incoming(void)
-#else
 comm_select_dns_incoming(void)
-#endif
 {
     int nfds = 0;
     int fds[2];
@@ -920,11 +592,7 @@
     if (DnsSocket < 0)
 	return;
     fds[nfds++] = DnsSocket;
-#if HAVE_POLL
-    nevents = comm_check_incoming_poll_handlers(nfds, fds);
-#else
     nevents = comm_check_incoming_select_handlers(nfds, fds);
-#endif
     if (nevents < 0)
 	return;
     incoming_dns_interval += Config.comm_incoming.dns_average - nevents;
@@ -940,10 +608,8 @@
 void
 comm_select_init(void)
 {
-#if !HAVE_POLL
     zero_tv.tv_sec = 0;
     zero_tv.tv_usec = 0;
-#endif
     cachemgrRegister("comm_incoming",
 	"comm_incoming() stats",
 	commIncomingStats, 0, 1);
@@ -952,7 +618,6 @@
     nreadfds = nwritefds = 0;
 }
 
-#if !HAVE_POLL
 /*
  * examine_select - debug routine.
  *
@@ -1018,34 +683,7 @@
     }
     return 0;
 }
-#endif
 
-static void
-checkTimeouts(void)
-{
-    int fd;
-    fde *F = NULL;
-    PF *callback;
-    for (fd = 0; fd <= Biggest_FD; fd++) {
-	F = &fd_table[fd];
-	if (!F->flags.open)
-	    continue;
-	if (F->timeout == 0)
-	    continue;
-	if (F->timeout > squid_curtime)
-	    continue;
-	debug(5, 5) ("checkTimeouts: FD %d Expired\n", fd);
-	if (F->timeout_handler) {
-	    debug(5, 5) ("checkTimeouts: FD %d: Call timeout handler\n", fd);
-	    callback = F->timeout_handler;
-	    F->timeout_handler = NULL;
-	    callback(fd, F->timeout_data);
-	} else {
-	    debug(5, 5) ("checkTimeouts: FD %d: Forcing comm_close()\n", fd);
-	    comm_close(fd);
-	}
-    }
-}
 
 static void
 commIncomingStats(StoreEntry * sentry)
@@ -1059,23 +697,11 @@
 	incoming_http_interval >> INCOMING_FACTOR);
     storeAppendPrintf(sentry, "\n");
     storeAppendPrintf(sentry, "Histogram of events per incoming socket type\n");
-#ifdef HAVE_POLL
-    storeAppendPrintf(sentry, "ICP Messages handled per comm_poll_icp_incoming() call:\n");
-#else
     storeAppendPrintf(sentry, "ICP Messages handled per comm_select_icp_incoming() call:\n");
-#endif
     statHistDump(&f->comm_icp_incoming, sentry, statHistIntDumper);
-#ifdef HAVE_POLL
-    storeAppendPrintf(sentry, "DNS Messages handled per comm_poll_dns_incoming() call:\n");
-#else
     storeAppendPrintf(sentry, "DNS Messages handled per comm_select_dns_incoming() call:\n");
-#endif
     statHistDump(&f->comm_dns_incoming, sentry, statHistIntDumper);
-#ifdef HAVE_POLL
-    storeAppendPrintf(sentry, "HTTP Messages handled per comm_poll_http_incoming() call:\n");
-#else
     storeAppendPrintf(sentry, "HTTP Messages handled per comm_select_http_incoming() call:\n");
-#endif
     statHistDump(&f->comm_http_incoming, sentry, statHistIntDumper);
 }
 
@@ -1109,3 +735,5 @@
 {
     MAX_POLL_TIME = 10;
 }
+
+#endif /* USE_SELECT */
Index: src/fd.c
===================================================================
RCS file: /server/cvs-server/squid/squid/src/fd.c,v
retrieving revision 1.43
diff -u -a -r1.43 fd.c
--- src/fd.c	2001/08/26 22:24:56	1.43
+++ src/fd.c	2001/12/21 06:03:37
@@ -84,11 +84,11 @@
 	assert(F->write_handler == NULL);
     }
     debug(51, 3) ("fd_close FD %d %s\n", fd, F->desc);
+    commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0);
+    commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0);
     F->flags.open = 0;
     fdUpdateBiggest(fd, 0);
     Number_FD--;
-    commUpdateReadBits(fd, NULL);
-    commUpdateWriteBits(fd, NULL);
     memset(F, '\0', sizeof(fde));
     F->timeout = 0;
 }
Index: src/ipc.c
===================================================================
RCS file: /server/cvs-server/squid/squid/src/ipc.c,v
retrieving revision 1.26
diff -u -a -r1.26 ipc.c
--- src/ipc.c	2001/10/17 20:25:02	1.26
+++ src/ipc.c	2001/12/21 06:03:37
@@ -74,7 +74,7 @@
 #endif
     int x;
 
-#if HAVE_POLL && defined(_SQUID_OSF_)
+#if USE_POLL && defined(_SQUID_OSF_)
     assert(type != IPC_FIFO);
 #endif
 
Index: src/main.c
===================================================================
RCS file: /server/cvs-server/squid/squid/src/main.c,v
retrieving revision 1.345
diff -u -a -r1.345 main.c
--- src/main.c	2001/10/24 06:55:44	1.345
+++ src/main.c	2001/12/21 06:03:37
@@ -720,11 +720,7 @@
 	eventRun();
 	if ((loop_delay = eventNextTime()) < 0)
 	    loop_delay = 0;
-#if HAVE_POLL
-	switch (comm_poll(loop_delay)) {
-#else
 	switch (comm_select(loop_delay)) {
-#endif
 	case COMM_OK:
 	    errcount = 0;	/* reset if successful */
 	    break;
Index: src/protos.h
===================================================================
RCS file: /server/cvs-server/squid/squid/src/protos.h,v
retrieving revision 1.420
diff -u -a -r1.420 protos.h
--- src/protos.h	2001/11/13 21:27:48	1.420
+++ src/protos.h	2001/12/21 06:03:37
@@ -174,19 +174,15 @@
 extern void commSetDefer(int fd, DEFER * func, void *);
 extern int ignoreErrno(int);
 extern void commCloseAllSockets(void);
+extern void checkTimeouts(void);
+extern int commDeferRead(int fd);
 
 
 /*
  * comm_select.c
  */
 extern void comm_select_init(void);
-#if HAVE_POLL
-extern int comm_poll(int);
-#else
 extern int comm_select(int);
-#endif
-extern void commUpdateReadBits(int, PF *);
-extern void commUpdateWriteBits(int, PF *);
 extern void comm_quick_poll_required(void);
 
 extern void packerToStoreInit(Packer * p, StoreEntry * e);
Index: src/stat.c
===================================================================
RCS file: /server/cvs-server/squid/squid/src/stat.c,v
retrieving revision 1.351
diff -u -a -r1.351 stat.c
--- src/stat.c	2001/10/24 08:19:08	1.351
+++ src/stat.c	2001/12/21 06:03:37
@@ -801,9 +801,10 @@
     storeAppendPrintf(sentry, "aborted_requests = %f/sec\n",
 	XAVG(aborted_requests));
 
-#if HAVE_POLL
+#if USE_POLL
     storeAppendPrintf(sentry, "syscalls.polls = %f/sec\n", XAVG(syscalls.polls));
-#else
+#endif
+#if USE_SELECT
     storeAppendPrintf(sentry, "syscalls.selects = %f/sec\n", XAVG(syscalls.selects));
 #endif
     storeAppendPrintf(sentry, "syscalls.disk.opens = %f/sec\n", XAVG(syscalls.disk.opens));
Index: src/unlinkd.c
===================================================================
RCS file: /server/cvs-server/squid/squid/src/unlinkd.c,v
retrieving revision 1.44
diff -u -a -r1.44 unlinkd.c
--- src/unlinkd.c	2001/10/17 20:25:03	1.44
+++ src/unlinkd.c	2001/12/21 06:03:37
@@ -163,7 +163,7 @@
     struct timeval slp;
     args[0] = "(unlinkd)";
     args[1] = NULL;
-#if HAVE_POLL && defined(_SQUID_OSF_)
+#if USE_POLL && defined(_SQUID_OSF_)
     /* pipes and poll() don't get along on DUNIX -DW */
     x = ipcCreate(IPC_TCP_SOCKET,
 #else

