--------------------- PatchSet 3865 Date: 2002/04/04 19:40:21 Author: serassio Branch: nt-2_5 Tag: (none) Log: Updated WIN32 socket code Members: port/win32/include/autoconf.h:1.1.2.3->1.1.2.4 port/win32/include/squid-mswin.h:1.1.2.4->1.1.2.5 src/cache_manager.c:1.7.62.1->1.7.62.2 src/comm.c:1.18.6.1.2.3->1.18.6.1.2.4 src/comm_select.c:1.8.10.3->1.8.10.4 src/helper.c:1.16.10.1->1.16.10.2 src/icmp.c:1.4.74.1->1.4.74.2 src/main.c:1.28.6.1.4.2->1.28.6.1.4.3 src/protos.h:1.41.6.3.4.2->1.41.6.3.4.3 src/win32.c:1.5.14.3->1.5.14.4 Index: squid/port/win32/include/autoconf.h =================================================================== RCS file: /cvsroot/squid-sf//squid/port/win32/include/Attic/autoconf.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/port/win32/include/autoconf.h 27 Mar 2002 21:01:11 -0000 1.1.2.3 +++ squid/port/win32/include/autoconf.h 4 Apr 2002 19:40:21 -0000 1.1.2.4 @@ -22,7 +22,7 @@ * */ -/* $Id: autoconf.h,v 1.1.2.3 2002/03/27 21:01:11 serassio Exp $ */ +/* $Id: autoconf.h,v 1.1.2.4 2002/04/04 19:40:21 serassio Exp $ */ /* * configure command line used to configure Squid @@ -178,7 +178,7 @@ /* Maximum number of open filedescriptors */ #undef SQUID_MAXFD -#define SQUID_MAXFD 8192 +#define SQUID_MAXFD 2048 /* UDP send buffer size */ #undef SQUID_UDP_SO_SNDBUF Index: squid/port/win32/include/squid-mswin.h =================================================================== RCS file: /cvsroot/squid-sf//squid/port/win32/include/Attic/squid-mswin.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid/port/win32/include/squid-mswin.h 27 Mar 2002 21:01:11 -0000 1.1.2.4 +++ squid/port/win32/include/squid-mswin.h 4 Apr 2002 19:40:22 -0000 1.1.2.5 @@ -1,5 +1,5 @@ /* - * $Id: squid-mswin.h,v 1.1.2.4 2002/03/27 21:01:11 serassio Exp $ + * $Id: squid-mswin.h,v 1.1.2.5 2002/04/04 19:40:22 serassio Exp $ * * AUTHOR: Guido Serassio & Andrey Shorin * @@ -154,7 +154,7 @@ #define ECONNRESET WSAECONNRESET #define ERESTART WSATRY_AGAIN -/* internal to CTRLIB */ +/* internal to CRTLIB */ #define FPIPE 0x08 /* file handle refers to a pipe */ typedef struct { long osfhnd; /* underlying OS file HANDLE */ @@ -170,6 +170,7 @@ #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E) #define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)) ) #define _osfile(i) ( _pioinfo(i)->osfile ) +int __cdecl _free_osfhnd(int); #undef h_errno #define h_errno errno /* we'll set it ourselves */ @@ -177,9 +178,9 @@ #undef FD_CLR #define FD_CLR(fd, set) do { \ u_int __i; \ - SOCKET _sock = _get_osfhandle(fd); \ + SOCKET __sock = _get_osfhandle(fd); \ for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \ - if (((fd_set FAR *)(set))->fd_array[__i] == _sock) { \ + if (((fd_set FAR *)(set))->fd_array[__i] == __sock) { \ while (__i < ((fd_set FAR *)(set))->fd_count-1) { \ ((fd_set FAR *)(set))->fd_array[__i] = \ ((fd_set FAR *)(set))->fd_array[__i+1]; \ @@ -194,22 +195,22 @@ #undef FD_SET #define FD_SET(fd, set) do { \ u_int __i; \ - SOCKET _sock = _get_osfhandle(fd); \ + SOCKET __sock = _get_osfhandle(fd); \ for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) { \ - if (((fd_set FAR *)(set))->fd_array[__i] == (_sock)) { \ + if (((fd_set FAR *)(set))->fd_array[__i] == (__sock)) { \ break; \ } \ } \ if (__i == ((fd_set FAR *)(set))->fd_count) { \ if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) { \ - ((fd_set FAR *)(set))->fd_array[__i] = (_sock); \ + ((fd_set FAR *)(set))->fd_array[__i] = (__sock); \ ((fd_set FAR *)(set))->fd_count++; \ } \ } \ } while(0) #undef FD_ISSET -#define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)_get_osfhandle(fd), (fd_set FAR *)(set)) +#define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(_get_osfhandle(fd)), (fd_set FAR *)(set)) extern __declspec(thread) int ws32_result; @@ -244,17 +245,15 @@ (SOCKET_ERROR == shutdown(_get_osfhandle(s),h) ? \ (errno = WSAGetLastError()), -1 : 0) #define closesocket(s) \ + { \ (SOCKET_ERROR == closesocket(_get_osfhandle(s)) ? \ - (errno = WSAGetLastError()), -1 : 0) -#if defined(COMM_SELECT_C) -#define select(n,r,w,e,t) \ - (SOCKET_ERROR == (ws32_result = select(n,r,w,&errfds,t)) ? \ - ((errno = WSAGetLastError()), -1) : ws32_result) -#else + (errno = WSAGetLastError()), -1 : 0); \ + _free_osfhnd(s); \ + _osfile(s) = 0; \ + } #define select(n,r,w,e,t) \ (SOCKET_ERROR == (ws32_result = select(n,r,w,e,t)) ? \ ((errno = WSAGetLastError()), -1) : ws32_result) -#endif #define recv(s,b,l,f) \ (SOCKET_ERROR == (ws32_result = recv(_get_osfhandle(s),b,l,f)) ? \ ((errno = WSAGetLastError()), -1) : ws32_result) Index: squid/src/cache_manager.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cache_manager.c,v retrieving revision 1.7.62.1 retrieving revision 1.7.62.2 diff -u -r1.7.62.1 -r1.7.62.2 --- squid/src/cache_manager.c 27 Mar 2002 21:01:14 -0000 1.7.62.1 +++ squid/src/cache_manager.c 4 Apr 2002 19:40:22 -0000 1.7.62.2 @@ -1,6 +1,6 @@ /* - * $Id: cache_manager.c,v 1.7.62.1 2002/03/27 21:01:14 serassio Exp $ + * $Id: cache_manager.c,v 1.7.62.2 2002/04/04 19:40:22 serassio Exp $ * * DEBUG: section 16 Cache Manager Objects * AUTHOR: Duane Wessels @@ -291,6 +291,16 @@ storeAppendPrintf(sentry, "Reconfiguring Squid Process ...."); } +#if defined(_SQUID_MSWIN_) && defined(_DEBUG) +static void +cachemgrBreak(StoreEntry * sentry) +{ + debug(16, 0) ("Break by command.\n"); + sigusr2_handle(SIGUSR2); + storeAppendPrintf(sentry, "Breaking Squid Process ...."); +} +#endif + static void cachemgrOfflineToggle(StoreEntry * sentry) { @@ -354,6 +364,11 @@ cachemgrRegister("reconfigure", "Reconfigure the Squid Process", cachemgrReconfigure, 1, 1); +#if defined(_SQUID_MSWIN_) && defined(_DEBUG) + cachemgrRegister("break", + "Break the Squid Process", + cachemgrBreak, 1, 1); +#endif cachemgrRegister("offline_toggle", "Toggle offline_mode setting", cachemgrOfflineToggle, 1, 1); Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.18.6.1.2.3 retrieving revision 1.18.6.1.2.4 diff -u -r1.18.6.1.2.3 -r1.18.6.1.2.4 --- squid/src/comm.c 17 Mar 2002 18:16:06 -0000 1.18.6.1.2.3 +++ squid/src/comm.c 4 Apr 2002 19:40:22 -0000 1.18.6.1.2.4 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.18.6.1.2.3 2002/03/17 18:16:06 serassio Exp $ + * $Id: comm.c,v 1.18.6.1.2.4 2002/04/04 19:40:22 serassio Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -216,9 +216,9 @@ if ((flags & COMM_REUSEADDR)) commSetReuseAddr(new_socket); if (port > (u_short) 0) { -#ifdef _SQUID_MSWIN_ - if (sock_type != SOCK_DGRAM) -#endif +#ifdef _SQUID_MSWIN_ + if (sock_type != SOCK_DGRAM) +#endif commSetNoLinger(new_socket); if (opt_reuseaddr) commSetReuseAddr(new_socket); @@ -743,7 +743,6 @@ fd_table[fd].close_handler = p->next; cbdataUnlock(p->data); memPoolFree(conn_close_pool, p); /* AAA */ - } static void Index: squid/src/comm_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_select.c,v retrieving revision 1.8.10.3 retrieving revision 1.8.10.4 diff -u -r1.8.10.3 -r1.8.10.4 --- squid/src/comm_select.c 27 Mar 2002 21:01:17 -0000 1.8.10.3 +++ squid/src/comm_select.c 4 Apr 2002 19:40:22 -0000 1.8.10.4 @@ -1,6 +1,6 @@ /* - * $Id: comm_select.c,v 1.8.10.3 2002/03/27 21:01:17 serassio Exp $ + * $Id: comm_select.c,v 1.8.10.4 2002/04/04 19:40:22 serassio Exp $ * * DEBUG: section 5 Socket Functions * @@ -564,7 +564,11 @@ getCurrentTime(); #endif 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]; @@ -704,11 +708,17 @@ /* remove stalled FDs, and deal with pending descriptors */ pending = 0; for (j = 0; j < (int) readfds.fd_count; j++) { + no_bits = 1; for ( fd = Biggest_FD; fd; fd-- ) { - if ( _get_osfhandle(fd) == readfds.fd_array[j] ) - break; + if ( _get_osfhandle(fd) == readfds.fd_array[j] ) { + if (fd_table[fd].flags.open) { + no_bits = 0; + break; + } + } } - assert(fd); + if (no_bits) + continue; switch (commDeferRead(fd)) { case 0: break; @@ -797,7 +807,11 @@ 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 || pending > 0) break; @@ -826,13 +840,15 @@ #ifdef _SQUID_MSWIN_ assert(readfds.fd_count <= (unsigned int) Biggest_FD); assert(pendingfds.fd_count <= (unsigned int) Biggest_FD); - no_bits = 1; for (j = 0; j < (int) readfds.fd_count; j++) { + no_bits = 1; for ( fd = Biggest_FD; fd; fd-- ) { if (( _get_osfhandle(fd) == readfds.fd_array[j] ) || ( _get_osfhandle(fd) == pendingfds.fd_array[j] )) { - no_bits = 0; - break; + if (fd_table[fd].flags.open) { + no_bits = 0; + break; + } } } if (no_bits) @@ -898,28 +914,30 @@ if ( _get_osfhandle(fd) == errfds.fd_array[j] ) break; } - assert(fd); - F = &fd_table[fd]; - if ((hdl = F->write_handler)) { - F->write_handler = NULL; - commUpdateWriteBits(fd, NULL); - hdl(fd, F->write_data); - statCounter.select_fds++; + 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++; + } } } #endif assert(writefds.fd_count <= (unsigned int) Biggest_FD); - no_bits = 1; for (j = 0; j < (int) writefds.fd_count; j++) { + no_bits = 1; for ( fd = Biggest_FD; fd; fd-- ) { if ( _get_osfhandle(fd) == writefds.fd_array[j] ) { - no_bits = 0; - break; + if (fd_table[fd].flags.open) { + no_bits = 0; + break; + } } } if (no_bits) continue; - assert(fd >= 0); #else } fdsp = (fd_mask *) & writefds; @@ -1118,25 +1136,10 @@ static void checkTimeouts(void) { -#ifdef _SQUID_MSWIN_ - int j; - fd_set readfds; - fd_set writefds; -#endif int fd; fde *F = NULL; PF *callback; -#ifdef _SQUID_MSWIN_ - xmemcpy(&readfds, &global_readfds, sizeof(global_readfds)); - xmemcpy(&writefds, &global_writefds, sizeof(global_writefds)); - for (j = 0; j < (int) readfds.fd_count; j++) { - for ( fd = Biggest_FD; fd; fd-- ) { - if ( _get_osfhandle(fd) == readfds.fd_array[j] ) - break; - } -#else for (fd = 0; fd <= Biggest_FD; fd++) { -#endif F = &fd_table[fd]; if (!F->flags.open) continue; @@ -1155,31 +1158,6 @@ comm_close(fd); } } -#ifdef _SQUID_MSWIN_ - for (j = 0; j < (int) writefds.fd_count; j++) { - for ( fd = Biggest_FD; fd; fd-- ) { - if ( _get_osfhandle(fd) == writefds.fd_array[j] ) - break; - } - 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); - } - } -#endif } static void Index: squid/src/helper.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/helper.c,v retrieving revision 1.16.10.1 retrieving revision 1.16.10.2 diff -u -r1.16.10.1 -r1.16.10.2 --- squid/src/helper.c 14 Mar 2002 20:23:44 -0000 1.16.10.1 +++ squid/src/helper.c 4 Apr 2002 19:40:22 -0000 1.16.10.2 @@ -1,6 +1,6 @@ /* - * $Id: helper.c,v 1.16.10.1 2002/03/14 20:23:44 serassio Exp $ + * $Id: helper.c,v 1.16.10.2 2002/04/04 19:40:22 serassio Exp $ * * DEBUG: section 29 Helper process maintenance * AUTHOR: Harvest Derived? @@ -164,11 +164,11 @@ int rfd; int wfd; wordlist *w; -#ifdef _SQUID_MSWIN_ - HANDLE hIpc; - pid_t pid; -#endif - +#ifdef _SQUID_MSWIN_ + HANDLE hIpc; + pid_t pid; +#endif + if (hlp->cmdline == NULL) return; progname = hlp->cmdline->key; @@ -193,11 +193,11 @@ args, shortname, &rfd, - &wfd -#ifdef _SQUID_MSWIN_ - , &hIpc, &pid -#endif - ); + &wfd +#ifdef _SQUID_MSWIN_ + , &hIpc, &pid +#endif + ); if (x < 0) { debug(29, 1) ("WARNING: Cannot run '%s' process.\n", progname); continue; Index: squid/src/icmp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icmp.c,v retrieving revision 1.4.74.1 retrieving revision 1.4.74.2 diff -u -r1.4.74.1 -r1.4.74.2 --- squid/src/icmp.c 27 Mar 2002 21:01:17 -0000 1.4.74.1 +++ squid/src/icmp.c 4 Apr 2002 19:40:22 -0000 1.4.74.2 @@ -1,6 +1,6 @@ /* - * $Id: icmp.c,v 1.4.74.1 2002/03/27 21:01:17 serassio Exp $ + * $Id: icmp.c,v 1.4.74.2 2002/04/04 19:40:22 serassio Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels @@ -196,7 +196,7 @@ icmpOpen(void) { #if USE_ICMP - char *args[2]; + const char *args[2]; int x; int rfd; int wfd; Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.28.6.1.4.2 retrieving revision 1.28.6.1.4.3 diff -u -r1.28.6.1.4.2 -r1.28.6.1.4.3 --- squid/src/main.c 27 Mar 2002 21:01:18 -0000 1.28.6.1.4.2 +++ squid/src/main.c 4 Apr 2002 19:40:22 -0000 1.28.6.1.4.3 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.28.6.1.4.2 2002/03/27 21:01:18 serassio Exp $ + * $Id: main.c,v 1.28.6.1.4.3 2002/04/04 19:40:22 serassio Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -559,6 +559,9 @@ #endif debug(1, 1) ("Process ID %d\n", (int) getpid()); debug(1, 1) ("With %d file descriptors available\n", Squid_MaxFD); +#ifdef _SQUID_MSWIN_ + debug(1, 1) ("With %d CRT stdio descriptors available\n", _getmaxstdio()); +#endif if (!configured_once) disk_init(); /* disk_init must go before ipcache_init() */ Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.41.6.3.4.2 retrieving revision 1.41.6.3.4.3 diff -u -r1.41.6.3.4.2 -r1.41.6.3.4.3 --- squid/src/protos.h 17 Mar 2002 18:16:06 -0000 1.41.6.3.4.2 +++ squid/src/protos.h 4 Apr 2002 19:40:23 -0000 1.41.6.3.4.3 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.41.6.3.4.2 2002/03/17 18:16:06 serassio Exp $ + * $Id: protos.h,v 1.41.6.3.4.3 2002/04/04 19:40:23 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1204,10 +1204,10 @@ const char *const args[], const char *name, int *rfd, - int *wfd -#ifdef _SQUID_MSWIN_ - , HANDLE * hIpc, pid_t * ppid -#endif + int *wfd +#ifdef _SQUID_MSWIN_ + , HANDLE * hIpc, pid_t * ppid +#endif ); /* CacheDigest */ @@ -1341,8 +1341,8 @@ extern void WIN32_SetServiceCommandLine(void); extern void WIN32_InstallService(void); extern void WIN32_RemoveService(void); -extern int WIN32_getrusage(int, struct rusage *); -extern int WIN32_is_interface_down(const char *); +extern int WIN32_getrusage(int, struct rusage *); +extern int WIN32_is_interface_down(const char *); #endif #endif /* SQUID_PROTOS_H */ Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.5.14.3 retrieving revision 1.5.14.4 diff -u -r1.5.14.3 -r1.5.14.4 --- squid/src/win32.c 27 Mar 2002 21:01:18 -0000 1.5.14.3 +++ squid/src/win32.c 4 Apr 2002 19:40:23 -0000 1.5.14.4 @@ -393,6 +393,12 @@ WIN32_build_argv(WIN32_Service_Command_Line); *argc = WIN32_argc; *argv = WIN32_argv; +#ifdef _SQUID_MSWIN_ + close(0); + close(1); + close(2); + _setmaxstdio(Squid_MaxFD); +#endif } #endif #ifdef _SQUID_MSWIN_