--------------------- PatchSet 8205 Date: 2006/06/10 15:57:36 Author: serassio Branch: nt Tag: (none) Log: Now select() on Windows works again Members: src/comm_select_win32.c:1.1.2.9->1.1.2.10 Index: squid/src/comm_select_win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_select_win32.c,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -r1.1.2.9 -r1.1.2.10 --- squid/src/comm_select_win32.c 4 Jun 2006 14:12:15 -0000 1.1.2.9 +++ squid/src/comm_select_win32.c 10 Jun 2006 15:57:36 -0000 1.1.2.10 @@ -1,6 +1,6 @@ /* - * $Id: comm_select_win32.c,v 1.1.2.9 2006/06/04 14:12:15 serassio Exp $ + * $Id: comm_select_win32.c,v 1.1.2.10 2006/06/10 15:57:36 serassio Exp $ * * DEBUG: section 5 Socket Functions * @@ -39,11 +39,6 @@ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) #endif -#ifndef NBBY -#define NBBY 8 -#endif -#define FD_MASK_BYTES sizeof(fd_mask) -#define FD_MASK_BITS (FD_MASK_BYTES*NBBY) /* STATIC */ static int examine_select(fd_set *, fd_set *); @@ -299,7 +294,7 @@ int num; int callicp = 0, callhttp = 0; int calldns = 0; - int j; + register int j; static time_t last_timeout = 0; struct timeval poll_time; double timeout = current_dtime + (msec / 1000.0); @@ -397,56 +392,16 @@ } if (num == 0) continue; - 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]; - fde *F; - 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]; - debug(5, 6) ("comm_select: FD %d ready for %s\n", fd, - __WSAFDIsSet(fd_table[fd].win32.handle, &errfds) ? "write" : ""); - if (F->write_handler) { - int do_write = 0; - switch (F->write_pending) { - case COMM_PENDING_WANTS_READ: - do_write = __WSAFDIsSet(fd_table[fd].win32.handle, &readfds); - break; - case COMM_PENDING_NORMAL: - case COMM_PENDING_WANTS_WRITE: - do_write = __WSAFDIsSet(fd_table[fd].win32.handle, &writefds); - break; - case COMM_PENDING_NOW: - do_write = 1; - break; - } - if (do_write) { - PF *hdl = F->write_handler; - void *hdl_data = F->write_data; - debug(5, 6) ("comm_select: FD %d calling write_handler %p(%p)\n", fd, hdl, hdl_data); - commUpdateWriteHandler(fd, NULL, NULL); - hdl(fd, hdl_data); - statCounter.select_fds++; - } - } - } - } - /* Scan return fd masks for ready descriptors */ + /* Scan return fd masks for ready read descriptors */ assert(readfds.fd_count <= (unsigned int) Biggest_FD); - assert(writefds.fd_count <= (unsigned int) Biggest_FD); - for (j = 0; j < (int) max(readfds.fd_count, writefds.fd_count); j++) { + for (j = 0; j < (int) readfds.fd_count; j++) { register int readfds_handle = readfds.fd_array[j]; - register int writefds_handle = writefds.fd_array[j]; register int osfhandle; fde *F; no_bits = 1; for (fd = Biggest_FD; fd; fd--) { osfhandle = fd_table[fd].win32.handle; - if ((osfhandle == readfds_handle) || - (osfhandle == writefds_handle)) { + if (osfhandle == readfds_handle) { if (fd_table[fd].flags.open) { no_bits = 0; break; @@ -468,9 +423,7 @@ continue; } F = &fd_table[fd]; - debug(5, 6) ("comm_select: FD %d ready for %s%s\n", fd, - __WSAFDIsSet(fd_table[fd].win32.handle, &readfds) ? "read" : "", - __WSAFDIsSet(fd_table[fd].win32.handle, &writefds) ? "write" : ""); + debug(5, 6) ("comm_select: FD %d ready for read\n", fd); if (F->read_handler) { int do_read = 0; switch (F->read_pending) { @@ -505,6 +458,59 @@ comm_select_http_incoming(); } } + } + /* Scan return fd masks for connect(0) error descriptors */ + 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) { + if (fd_table[fd].flags.open) { + fde *F = &fd_table[fd]; + if (F->write_handler) { + PF *hdl = F->write_handler; + void *hdl_data = F->write_data; + commUpdateWriteHandler(fd, NULL, NULL); + hdl(fd, hdl_data); + statCounter.select_fds++; + } + } + break; + } + } + } + /* Scan return fd masks for ready write descriptors */ + 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]; + register int osfhandle; + fde *F; + no_bits = 1; + for (fd = Biggest_FD; fd; fd--) { + osfhandle = fd_table[fd].win32.handle; + if (osfhandle == writefds_handle) { + if (fd_table[fd].flags.open) { + no_bits = 0; + break; + } + } + } + if (no_bits) + continue; + if (fdIsIcp(fd)) { + callicp = 1; + continue; + } + if (fdIsDns(fd)) { + calldns = 1; + continue; + } + if (fdIsHttp(fd)) { + callhttp = 1; + continue; + } + F = &fd_table[fd]; + debug(5, 6) ("comm_select: FD %d ready for write\n", fd); if (F->write_handler) { int do_write = 0; switch (F->write_pending) { @@ -535,7 +541,7 @@ } } } - if (callicp) + if (callicp) comm_select_icp_incoming(); if (calldns) comm_select_dns_incoming(); @@ -697,19 +703,19 @@ } void -commSetEvents(int fd, int need_read, int need_write, int force) +commSetEvents(int fd, int need_read, int need_write) { - if (need_read && !FD_ISSET(fd, &global_readfds)) { + if (need_read && !__WSAFDIsSet(fd_table[fd].win32.handle, &global_readfds)) { FD_SET(fd, &global_readfds); nreadfds++; - } else if (!need_read && FD_ISSET(fd, &global_readfds)) { + } else if (!need_read && __WSAFDIsSet(fd_table[fd].win32.handle, &global_readfds)) { FD_CLR(fd, &global_readfds); nreadfds--; } - if (need_write && !FD_ISSET(fd, &global_writefds)) { + if (need_write && !__WSAFDIsSet(fd_table[fd].win32.handle, &global_writefds)) { FD_SET(fd, &global_writefds); nwritefds++; - } else if (!need_write && FD_ISSET(fd, &global_writefds)) { + } else if (!need_write && __WSAFDIsSet(fd_table[fd].win32.handle, &global_writefds)) { FD_CLR(fd, &global_writefds); nwritefds--; }