--------------------- PatchSet 3745 Date: 2002/03/17 21:44:21 Author: serassio Branch: nt-2_5 Tag: (none) Log: Added WIN32 specific stuff - more work Members: port/win32/include/squid-mswin.h:1.1.2.1->1.1.2.2 src/comm_select.c:1.8->1.8.10.1 src/debug.c:1.9.10.1->1.9.10.2 src/fd.c:1.7.16.1->1.7.16.2 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.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/port/win32/include/squid-mswin.h 17 Mar 2002 18:18:04 -0000 1.1.2.1 +++ squid/port/win32/include/squid-mswin.h 17 Mar 2002 21:44:21 -0000 1.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: squid-mswin.h,v 1.1.2.1 2002/03/17 18:18:04 serassio Exp $ + * $Id: squid-mswin.h,v 1.1.2.2 2002/03/17 21:44:21 serassio Exp $ * * AUTHOR: Guido Serassio & Andrey Shorin * @@ -290,7 +290,7 @@ (NULL == ((HOSTENT FAR*)ws32_result = gethostbyaddr(a,l,t)) ? \ (errno = WSAGetLastError()), NULL : (HOSTENT FAR*)ws32_result) -#if defined(STORE_IO_C) || defined(STORE_DIR_C) || defined(TOOLS_C) || defined(UTIL_C) +#if defined(STORE_IO_C) || defined(STORE_DIR_C) || defined(UTIL_C) #define read _read #define write _write #else Index: squid/src/comm_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_select.c,v retrieving revision 1.8 retrieving revision 1.8.10.1 diff -u -r1.8 -r1.8.10.1 --- squid/src/comm_select.c 24 Oct 2001 09:42:12 -0000 1.8 +++ squid/src/comm_select.c 17 Mar 2002 21:44:21 -0000 1.8.10.1 @@ -1,6 +1,6 @@ /* - * $Id: comm_select.c,v 1.8 2001/10/24 09:42:12 squidadm Exp $ + * $Id: comm_select.c,v 1.8.10.1 2002/03/17 21:44:21 serassio Exp $ * * DEBUG: section 5 Socket Functions * @@ -32,6 +32,8 @@ * */ +#ifndef COMM_SELECT_C +#define COMM_SELECT_C #include "squid.h" static int MAX_POLL_TIME = 1000; /* see also comm_quick_poll_required() */ @@ -536,6 +538,10 @@ PF *hdl = NULL; 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; @@ -655,19 +661,25 @@ int pending; int callicp = 0, callhttp = 0; int calldns = 0; - int maxindex; - int k; int j; #if DEBUG_FDBITS int i; #endif - fd_mask *fdsp; fd_mask *pfdsp; - fd_mask tmask; static time_t last_timeout = 0; struct timeval poll_time; double timeout = current_dtime + (msec / 1000.0); - fde *F; + fde *F; +#ifdef _SQUID_MSWIN_ + int no_bits; + fd_set errfds; + FD_ZERO(&errfds); +#else + int k; + fd_mask *fdsp; + fd_mask tmask; + int maxindex; +#endif do { #if !ALARM_UPDATES_TIME getCurrentTime(); @@ -684,7 +696,38 @@ if (commCheckHTTPIncoming) comm_select_http_incoming(); callicp = calldns = callhttp = 0; - maxfd = Biggest_FD + 1; + maxfd = Biggest_FD + 1; +#ifdef _SQUID_MSWIN_ + xmemcpy(&readfds, &global_readfds, sizeof(global_readfds)); + xmemcpy(&writefds, &global_writefds, sizeof(global_writefds)); + /* remove stalled FDs, and deal with pending descriptors */ + pending = 0; + for (j = 0; j < (int) readfds.fd_count; j++) { + for ( fd = Biggest_FD; fd; fd-- ) { + if ( _get_osfhandle(fd) == readfds.fd_array[j] ) + break; + } + assert(fd); + switch (commDeferRead(fd)) { + case 0: + break; + case 1: + FD_CLR(fd, &readfds); + 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].flags.read_pending) { + FD_SET(fd, &pendingfds); + pending++; + } + } + } +#else xmemcpy(&readfds, &global_readfds, howmany(maxfd, FD_MASK_BITS) * FD_MASK_BYTES); xmemcpy(&writefds, &global_writefds, @@ -721,6 +764,7 @@ } } } +#endif #if DEBUG_FDBITS for (i = 0; i < maxfd; i++) { /* Check each open socket for a handler. */ @@ -778,6 +822,19 @@ if (num == 0 && pending == 0) continue; /* Scan return fd masks for ready descriptors */ +#ifdef _SQUID_MSWIN_ + assert(readfds.fd_count <= (unsigned int) Biggest_FD); + no_bits = 1; + for (j = 0; j < (int) readfds.fd_count; j++) { + for ( fd = Biggest_FD; fd; fd-- ) { + if ( _get_osfhandle(fd) == readfds.fd_array[j] ) { + no_bits = 0; + break; + } + } + if (no_bits) + continue; +#else fdsp = (fd_mask *) & readfds; pfdsp = (fd_mask *) & pendingfds; maxindex = howmany(maxfd, FD_MASK_BITS); @@ -792,6 +849,7 @@ /* Found a set bit */ fd = (j * FD_MASK_BITS) + k; EBIT_CLR(tmask, k); /* this will be done */ +#endif #if DEBUG_FDBITS debug(5, 9) ("FD %d bit set for reading\n", fd); assert(FD_ISSET(fd, &readfds)); @@ -829,6 +887,37 @@ comm_select_http_incoming(); } } +#ifdef _SQUID_MSWIN_ +#if 1 + assert(errfds.fd_count <= (unsigned int) Biggest_FD); + for (j = 0; j < (int) errfds.fd_count; j++) { + for ( fd = Biggest_FD; fd; fd-- ) { + 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++; + } + } +#endif + assert(writefds.fd_count <= (unsigned int) Biggest_FD); + no_bits = 1; + for (j = 0; j < (int) writefds.fd_count; j++) { + for ( fd = Biggest_FD; fd; fd-- ) { + if ( _get_osfhandle(fd) == writefds.fd_array[j] ) { + no_bits = 0; + break; + } + } + if (no_bits) + continue; + assert(fd >= 0); +#else } fdsp = (fd_mask *) & writefds; for (j = 0; j < maxindex; j++) { @@ -842,6 +931,7 @@ /* Found a set bit */ fd = (j * FD_MASK_BITS) + k; EBIT_CLR(tmask, k); /* this will be done */ +#endif #if DEBUG_FDBITS debug(5, 9) ("FD %d bit set for writing\n", fd); assert(FD_ISSET(fd, &writefds)); @@ -871,7 +961,9 @@ comm_select_dns_incoming(); if (commCheckHTTPIncoming) comm_select_http_incoming(); - } +#ifndef _SQUID_MSWIN_ + } +#endif } } if (callicp) @@ -1109,3 +1201,4 @@ { MAX_POLL_TIME = 10; } +#endif Index: squid/src/debug.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/debug.c,v retrieving revision 1.9.10.1 retrieving revision 1.9.10.2 diff -u -r1.9.10.1 -r1.9.10.2 --- squid/src/debug.c 16 Mar 2002 10:31:31 -0000 1.9.10.1 +++ squid/src/debug.c 17 Mar 2002 21:44:21 -0000 1.9.10.2 @@ -1,6 +1,6 @@ /* - * $Id: debug.c,v 1.9.10.1 2002/03/16 10:31:31 serassio Exp $ + * $Id: debug.c,v 1.9.10.2 2002/03/17 21:44:21 serassio Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -235,6 +235,9 @@ i--; snprintf(from, MAXPATHLEN, "%s.%d", debug_log_file, i - 1); snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, i); +#ifdef _SQUID_MSWIN_ + remove(to); +#endif rename(from, to); } /* @@ -248,6 +251,9 @@ /* Rotate the current log to .0 */ if (Config.Log.rotateNumber > 0) { snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, 0); +#ifdef _SQUID_MSWIN_ + remove(to); +#endif rename(debug_log_file, to); } /* Close and reopen the log. It may have been renamed "manually" Index: squid/src/fd.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fd.c,v retrieving revision 1.7.16.1 retrieving revision 1.7.16.2 diff -u -r1.7.16.1 -r1.7.16.2 --- squid/src/fd.c 14 Mar 2002 20:23:43 -0000 1.7.16.1 +++ squid/src/fd.c 17 Mar 2002 21:44:22 -0000 1.7.16.2 @@ -1,6 +1,6 @@ /* - * $Id: fd.c,v 1.7.16.1 2002/03/14 20:23:43 serassio Exp $ + * $Id: fd.c,v 1.7.16.2 2002/03/17 21:44:22 serassio Exp $ * * DEBUG: section 51 Filedescriptor Functions * AUTHOR: Duane Wessels @@ -37,6 +37,12 @@ int default_read_method(int, char *, int); int default_write_method(int, const char *, int); +#ifdef _SQUID_MSWIN_ +int socket_read_method(int, char *, int); +int socket_write_method(int, const char *, int); +int file_read_method(int, char *, int); +int file_write_method(int, const char *, int); +#endif const char *fdTypeStr[] = { @@ -92,25 +98,43 @@ memset(F, '\0', sizeof(fde)); F->timeout = 0; } + + +#ifdef _SQUID_MSWIN_ +int +socket_read_method(int fd, char *buf, int len) +{ + return (recv(fd, buf, len, 0)); +} + +int +file_read_method(int fd, char *buf, int len) +{ + return (fread(buf, 1, len, fd_table[fd].fbuf)); +} + +int +socket_write_method(int fd, const char *buf, int len) +{ + return (send(fd, buf, len, 0)); +} + +file_write_method(int fd, const char *buf, int len) +{ + return (fwrite(buf, 1, len, fd_table[fd].fbuf)); +} +#endif int default_read_method(int fd, char *buf, int len) { -#ifdef _SQUID_MSWIN_ - return (fread(buf, 1, len, fd_table[fd].fbuf)); -#else return (read(fd, buf, len)); -#endif } int default_write_method(int fd, const char *buf, int len) { -#ifdef _SQUID_MSWIN_ - return (fwrite(buf, 1, len, fd_table[fd].fbuf)); -#else return (write(fd, buf, len)); -#endif } void @@ -126,9 +150,27 @@ assert(!F->flags.open); debug(51, 3) ("fd_open FD %d %s\n", fd, desc); F->type = type; - F->flags.open = 1; - F->read_method = &default_read_method; - F->write_method = &default_write_method; + F->flags.open = 1; +#ifdef _SQUID_MSWIN_ + switch (type) { + case FD_SOCKET: + case FD_PIPE: + F->read_method = &socket_read_method; + F->write_method = &socket_write_method; + break; + case FD_FILE: + case FD_LOG: + F->read_method = &file_read_method; + F->write_method = &file_write_method; + break; + default: + F->read_method = &default_read_method; + F->write_method = &default_write_method; + } +#else + F->read_method = &default_read_method; + F->write_method = &default_write_method; +#endif fdUpdateBiggest(fd, 1); if (desc) xstrncpy(F->desc, desc, FD_DESC_SZ);