--------------------- PatchSet 7984 Date: 2006/05/26 20:45:02 Author: serassio Branch: nt Tag: (none) Log: Splitted the Windows select() code into comm_select_win32.c Members: configure.in:1.87.2.13->1.87.2.14 src/Makefile.am:1.34.2.5->1.34.2.6 src/comm_select.c:1.18.8.5->1.18.8.6 Index: squid/configure.in =================================================================== RCS file: /cvsroot/squid-sf//squid/configure.in,v retrieving revision 1.87.2.13 retrieving revision 1.87.2.14 diff -u -r1.87.2.13 -r1.87.2.14 --- squid/configure.in 26 May 2006 20:27:14 -0000 1.87.2.13 +++ squid/configure.in 26 May 2006 20:45:02 -0000 1.87.2.14 @@ -3,7 +3,7 @@ dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.87.2.13 2006/05/26 20:27:14 serassio Exp $ +dnl $Id: configure.in,v 1.87.2.14 2006/05/26 20:45:02 serassio Exp $ dnl dnl dnl @@ -11,7 +11,7 @@ AC_CONFIG_AUX_DIR(cfgaux) AM_INIT_AUTOMAKE(squid, 2.6.DEVEL-NT-CVS) AM_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.87.2.13 $)dnl +AC_REVISION($Revision: 1.87.2.14 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -2191,8 +2191,16 @@ SELECT_TYPE="poll" AC_DEFINE(USE_POLL,1,[Use poll() for the IO loop]) elif test "$ac_cv_func_select" = "yes" ; then - SELECT_TYPE="select" - AC_DEFINE(USE_SELECT,1,[Use select() for the IO loop]) + case "$host_os" in + mingw|mingw32) + SELECT_TYPE="select_win32" + AC_DEFINE(USE_SELECT_WIN32,1,[Use Winsock select() for the IO loop]) + ;; + *) + SELECT_TYPE="select" + AC_DEFINE(USE_SELECT,1,[Use select() for the IO loop]) + ;; + esac else echo "Eep! Can't find poll, epoll, or select!" echo "I'll try select and hope for the best." @@ -2203,6 +2211,7 @@ AM_CONDITIONAL([USE_POLL], [test $SELECT_TYPE = poll]) AM_CONDITIONAL([USE_EPOLL], [test $SELECT_TYPE = epoll]) AM_CONDITIONAL([USE_SELECT], [test $SELECT_TYPE = select]) +AM_CONDITIONAL([USE_SELECT_WIN32], [test $SELECT_TYPE = select_win32]) dnl Yay! Another Linux brokenness. Its not good enough dnl to know that setresuid() exists, because RedHat 5.0 declares Index: squid/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Makefile.am,v retrieving revision 1.34.2.5 retrieving revision 1.34.2.6 diff -u -r1.34.2.5 -r1.34.2.6 --- squid/src/Makefile.am 26 May 2006 20:27:14 -0000 1.34.2.5 +++ squid/src/Makefile.am 26 May 2006 20:45:03 -0000 1.34.2.6 @@ -77,6 +77,9 @@ if USE_SELECT COMMLOOP_SOURCE = comm_select.c endif +if USE_SELECT_WIN32 +COMMLOOP_SOURCE = comm_select_win32.c +endif SUBDIRS = fs repl auth @@ -118,6 +121,7 @@ comm_epoll.c \ comm_poll.c \ comm_select.c \ + comm_select_win32.c \ win32.c squid_SOURCES = \ Index: squid/src/comm_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_select.c,v retrieving revision 1.18.8.5 retrieving revision 1.18.8.6 diff -u -r1.18.8.5 -r1.18.8.6 --- squid/src/comm_select.c 26 May 2006 20:27:15 -0000 1.18.8.5 +++ squid/src/comm_select.c 26 May 2006 20:45:03 -0000 1.18.8.6 @@ -1,6 +1,6 @@ /* - * $Id: comm_select.c,v 1.18.8.5 2006/05/26 20:27:15 serassio Exp $ + * $Id: comm_select.c,v 1.18.8.6 2006/05/26 20:45:03 serassio Exp $ * * DEBUG: section 5 Socket Functions * @@ -32,8 +32,6 @@ * */ -#ifndef COMM_SELECT_C -#define COMM_SELECT_C #include "squid.h" static int MAX_POLL_TIME = 1000; /* see also comm_quick_poll_required() */ @@ -187,10 +185,6 @@ int maxfd = 0; fd_set read_mask; fd_set write_mask; -#ifdef _SQUID_MSWIN_ - fd_set errfds; - FD_ZERO(&errfds); -#endif FD_ZERO(&read_mask); FD_ZERO(&write_mask); incoming_sockets_accepted = 0; @@ -211,11 +205,7 @@ return -1; getCurrentTime(); statCounter.syscalls.selects++; -#ifdef _SQUID_MSWIN_ - if (select(maxfd, &read_mask, &write_mask, &errfds, &zero_tv) < 1) -#else if (select(maxfd, &read_mask, &write_mask, NULL, &zero_tv) < 1) -#endif return incoming_sockets_accepted; for (i = 0; i < nfds; i++) { fd = fds[i]; @@ -307,6 +297,8 @@ int num; int callicp = 0, callhttp = 0; int calldns = 0; + int maxindex; + int k; int j; fd_mask *rfdsp; fd_mask *wfdsp; @@ -314,15 +306,6 @@ static time_t last_timeout = 0; struct timeval poll_time; double timeout = current_dtime + (msec / 1000.0); - fde *F; -#ifdef _SQUID_MSWIN_ - int no_bits; - fd_set errfds; - FD_ZERO(&errfds); -#else - int k; - int maxindex; -#endif do { double start; getCurrentTime(); @@ -340,49 +323,6 @@ comm_select_http_incoming(); callicp = calldns = callhttp = 0; maxfd = Biggest_FD + 1; -#ifdef _SQUID_MSWIN_ - xmemcpy(&readfds, &global_readfds, sizeof(global_readfds)); - xmemcpy(&writefds, &global_writefds, sizeof(global_writefds)); - xmemcpy(&errfds, &global_writefds, sizeof(global_writefds)); - /* remove stalled FDs, and deal with pending descriptors */ - pending = 0; - FD_ZERO(&pendingfds); - for (j = 0; j < (int) readfds.fd_count; j++) { - register int readfds_handle = readfds.fd_array[j]; - no_bits = 1; - for ( fd = Biggest_FD; fd; fd-- ) { - if ( fd_table[fd].win32.handle == readfds_handle ) { - if (fd_table[fd].flags.open) { - no_bits = 0; - break; - } - } - } - if (no_bits) - continue; - switch (commDeferRead(fd)) { - case 0: - break; - case 1: - FD_CLR(fd, &readfds); - /* FD_CLR() decrements readfds.fd_count, so we must */ - /* decrement too the counter j */ - j--; - break; -#if DELAY_POOLS - case -1: - FD_SET(fd, &slowfds); - break; -#endif - default: - fatalf("bad return value from commDeferRead(FD %d)\n", fd); - } - if (FD_ISSET(fd, &readfds) && fd_table[fd].read_pending) { - FD_SET(fd, &pendingfds); - pending++; - } - } -#else xmemcpy(&readfds, &global_readfds, howmany(maxfd, FD_MASK_BITS) * FD_MASK_BYTES); xmemcpy(&writefds, &global_writefds, @@ -422,7 +362,6 @@ } } } -#endif if (nreadfds + nwritefds == 0) { assert(shutting_down); return COMM_SHUTDOWN; @@ -433,11 +372,7 @@ poll_time.tv_sec = msec / 1000; poll_time.tv_usec = (msec % 1000) * 1000; statCounter.syscalls.selects++; -#ifdef _SQUID_MSWIN_ - num = select(maxfd, &readfds, &writefds, &errfds, &poll_time); -#else num = select(maxfd, &readfds, &writefds, NULL, &poll_time); -#endif statCounter.select_loops++; if (num >= 0) break; @@ -463,27 +398,6 @@ if (num == 0) continue; /* Scan return fd masks for ready descriptors */ -#ifdef _SQUID_MSWIN_ - assert(readfds.fd_count <= (unsigned int) Biggest_FD); - assert(pendingfds.fd_count <= (unsigned int) Biggest_FD); - for (j = 0; j < (int) max(readfds.fd_count, pendingfds.fd_count); j++) { - register int readfds_handle = readfds.fd_array[j]; - register int pendingfds_handle = pendingfds.fd_array[j]; - register int osfhandle; - no_bits = 1; - for ( fd = Biggest_FD; fd; fd-- ) { - osfhandle = fd_table[fd].win32.handle; - if (( osfhandle == readfds_handle ) || - ( osfhandle == pendingfds_handle )) { - if (fd_table[fd].flags.open) { - no_bits = 0; - break; - } - } - } - if (no_bits) - continue; -#else rfdsp = (fd_mask *) & readfds; wfdsp = (fd_mask *) & writefds; maxindex = howmany(maxfd, FD_MASK_BITS); @@ -499,7 +413,6 @@ /* Found a set bit */ fd = (j * FD_MASK_BITS) + k; EBIT_CLR(tmask, k); /* this will be done */ -#endif if (fdIsIcp(fd)) { callicp = 1; continue; @@ -550,80 +463,6 @@ comm_select_http_incoming(); } } - } -#ifdef _SQUID_MSWIN_ - assert(errfds.fd_count <= (unsigned int) Biggest_FD); - for (j = 0; j < (int) errfds.fd_count; j++) { - register int errfds_handle = errfds.fd_array[j]; - for ( fd = Biggest_FD; fd; fd-- ) { - if ( fd_table[fd].win32.handle == errfds_handle ) - break; - } - if (fd_table[fd].flags.open) { - F = &fd_table[fd]; - if ((hdl = F->write_handler)) { - F->write_handler = NULL; - commUpdateWriteBits(fd, NULL); - hdl(fd, F->write_data); - statCounter.select_fds++; - } - } - } - assert(writefds.fd_count <= (unsigned int) Biggest_FD); - for (j = 0; j < (int) writefds.fd_count; j++) { - register int writefds_handle = writefds.fd_array[j]; - no_bits = 1; - for ( fd = Biggest_FD; fd; fd-- ) { - if ( fd_table[fd].win32.handle == writefds_handle ) { - if (fd_table[fd].flags.open) { - no_bits = 0; - break; - } - } - } - if (no_bits) - continue; -#else - } - fdsp = (fd_mask *) & writefds; - for (j = 0; j < maxindex; j++) { - if ((tmask = fdsp[j]) == 0) - continue; /* no bits here */ - for (k = 0; k < FD_MASK_BITS; k++) { - if (tmask == 0) - break; /* no more bits left */ - if (!EBIT_TEST(tmask, k)) - continue; - /* Found a set bit */ - fd = (j * FD_MASK_BITS) + k; - EBIT_CLR(tmask, k); /* this will be done */ -#endif - if (fdIsIcp(fd)) { - callicp = 1; - continue; - } - if (fdIsDns(fd)) { - calldns = 1; - continue; - } - if (fdIsHttp(fd)) { - callhttp = 1; - continue; - } - F = &fd_table[fd]; - debug(5, 5) ("comm_select: FD %d ready for writing\n", fd); - if ((hdl = F->write_handler)) { - F->write_handler = NULL; - commUpdateWriteBits(fd, NULL); - hdl(fd, F->write_data); - statCounter.select_fds++; - if (commCheckICPIncoming) - comm_select_icp_incoming(); - if (commCheckDNSIncoming) - comm_select_dns_incoming(); - if (commCheckHTTPIncoming) - comm_select_http_incoming(); -#ifndef _SQUID_MSWIN_ if (F->write_handler) { int do_write = 0; switch (F->write_pending) { @@ -653,7 +492,6 @@ comm_select_http_incoming(); } } -#endif } } if (callicp) @@ -932,4 +770,3 @@ { MAX_POLL_TIME = 10; } -#endif /* COMM_SELECT_C */