]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/comm_select_win32.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / comm_select_win32.cc
index 17052d0740d7a9bd0dc8c77ec86c0f3af8393cc6..041fa4e3ce50d6df5136ffa5008df7d17f51f9c2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm_select_win32.cc,v 1.2 2006/09/02 10:39:53 adrian Exp $
+ * $Id$
  *
  * DEBUG: section 5     Socket Functions
  *
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
@@ -79,7 +79,7 @@ static int nwritefds;
  * of incoming ICP, then we need to check these sockets more than
  * if we just have HTTP.
  *
- * The variables 'incoming_icp_interval' and 'incoming_http_interval' 
+ * The variables 'incoming_icp_interval' and 'incoming_http_interval'
  * determine how many normal I/O events to process before checking
  * incoming sockets again.  Note we store the incoming_interval
  * multipled by a factor of (2^INCOMING_FACTOR) to have some
@@ -100,7 +100,7 @@ static int nwritefds;
  *  incoming_interval = incoming_interval + target_average - number_of_events_processed
  *
  * There are separate incoming_interval counters for both HTTP and ICP events
- * 
+ *
  * You can see the current values of the incoming_interval's, as well as
  * a histogram of 'incoming_events' by asking the cache manager
  * for 'comm_incoming', e.g.:
@@ -138,7 +138,7 @@ commSetSelect(int fd, unsigned int type, PF * handler, void *client_data,
     fde *F = &fd_table[fd];
     assert(fd >= 0);
     assert(F->flags.open);
-    debug(5, 5) ("commSetSelect: FD %d type %d\n", fd, type);
+    debugs(5, 5, "commSetSelect: FD " << fd << " type " << type);
 
     if (type & COMM_SELECT_READ) {
         F->read_handler = handler;
@@ -156,6 +156,10 @@ commSetSelect(int fd, unsigned int type, PF * handler, void *client_data,
         F->timeout = squid_curtime + timeout;
 }
 
+void
+commResetSelect(int fd)
+{
+}
 
 static int
 fdIsIcp(int fd)
@@ -191,36 +195,6 @@ fdIsHttp(int fd)
     return 0;
 }
 
-#if DELAY_POOLS
-static int slowfdcnt = 0;
-static int slowfdarr[SQUID_MAXFD];
-
-static void
-commAddSlowFd(int fd)
-{
-    assert(slowfdcnt < SQUID_MAXFD);
-    slowfdarr[slowfdcnt++] = fd;
-}
-
-static int
-commGetSlowFd(void)
-{
-    int whichfd, retfd;
-
-    if (!slowfdcnt)
-        return -1;
-
-    whichfd = squid_random() % slowfdcnt;
-
-    retfd = slowfdarr[whichfd];
-
-    slowfdarr[whichfd] = slowfdarr[--slowfdcnt];
-
-    return retfd;
-}
-
-#endif
-
 static int
 comm_check_incoming_select_handlers(int nfds, int *fds)
 {
@@ -268,25 +242,23 @@ comm_check_incoming_select_handlers(int nfds, int *fds)
     for (i = 0; i < nfds; i++) {
         fd = fds[i];
 
-        if (FD_ISSET(fd, &read_mask)) {
+        if (__WSAFDIsSet(fd_table[fd].win32.handle, &read_mask)) {
             if ((hdl = fd_table[fd].read_handler) != NULL) {
                 fd_table[fd].read_handler = NULL;
                 commUpdateReadBits(fd, NULL);
                 hdl(fd, fd_table[fd].read_data);
             } else {
-                debug(5, 1) ("comm_select_incoming: FD %d NULL read handler\n",
-                             fd);
+                debugs(5, 1, "comm_select_incoming: FD " << fd << " NULL read handler");
             }
         }
 
-        if (FD_ISSET(fd, &write_mask)) {
+        if (__WSAFDIsSet(fd_table[fd].win32.handle, &write_mask)) {
             if ((hdl = fd_table[fd].write_handler) != NULL) {
                 fd_table[fd].write_handler = NULL;
                 commUpdateWriteBits(fd, NULL);
                 hdl(fd, fd_table[fd].write_data);
             } else {
-                debug(5, 1) ("comm_select_incoming: FD %d NULL write handler\n",
-                             fd);
+                debugs(5, 1, "comm_select_incoming: FD " << fd << " NULL write handler");
             }
         }
     }
@@ -367,10 +339,6 @@ comm_select(int msec)
     fd_set readfds;
     fd_set pendingfds;
     fd_set writefds;
-#if DELAY_POOLS
-
-    fd_set slowfds;
-#endif
 
     PF *hdl = NULL;
     int fd;
@@ -396,10 +364,6 @@ comm_select(int msec)
         double start;
         getCurrentTime();
         start = current_dtime;
-#if DELAY_POOLS
-
-        FD_ZERO(&slowfds);
-#endif
 
         if (commCheckICPIncoming)
             comm_select_icp_incoming();
@@ -441,7 +405,7 @@ comm_select(int msec)
             if (no_bits)
                 continue;
 
-            if (FD_ISSET(fd, &readfds) && fd_table[fd].flags.read_pending) {
+            if (__WSAFDIsSet(fd_table[fd].win32.handle, &readfds) && fd_table[fd].flags.read_pending) {
                 FD_SET(fd, &pendingfds);
                 pending++;
             }
@@ -452,11 +416,11 @@ comm_select(int msec)
             /* Check each open socket for a handler. */
 
             if (fd_table[i].read_handler) {
-                assert(FD_ISSET(i, &readfds));
+                assert(__WSAFDIsSet(fd_table[i].win32.handle, readfds));
             }
 
             if (fd_table[i].write_handler) {
-                assert(FD_ISSET(i, &writefds));
+                assert(__WSAFDIsSet(fd_table[i].win32.handle, writefds));
             }
         }
 
@@ -469,9 +433,6 @@ comm_select(int msec)
         if (msec > MAX_POLL_TIME)
             msec = MAX_POLL_TIME;
 
-        if (comm_iocallbackpending())
-            pending++;
-
         if (pending)
             msec = 0;
 
@@ -488,8 +449,7 @@ comm_select(int msec)
             if (ignoreErrno(errno))
                 break;
 
-            debug(5, 0) ("comm_select: select failure: %s\n",
-                         xstrerror());
+            debugs(5, 0, "comm_select: select failure: " << xstrerror());
 
             examine_select(&readfds, &writefds);
 
@@ -503,8 +463,7 @@ comm_select(int msec)
 
         getCurrentTime();
 
-        debug(5, num ? 5 : 8) ("comm_select: %d+%d FDs ready\n",
-                               num, pending);
+        debugs(5, num ? 5 : 8, "comm_select: " << num << "+" << pending << " FDs ready");
 
         statHistCount(&statCounter.select_fds_hist, num);
 
@@ -512,9 +471,7 @@ comm_select(int msec)
             continue;
 
         /* Scan return fd masks for ready descriptors */
-
         assert(readfds.fd_count <= (unsigned int) Biggest_FD);
-
         assert(pendingfds.fd_count <= (unsigned int) Biggest_FD);
 
         for (j = 0; j < (int) readfds.fd_count; j++) {
@@ -540,9 +497,9 @@ comm_select(int msec)
 
 #if DEBUG_FDBITS
 
-            debug(5, 9) ("FD %d bit set for reading\n", fd);
+            debugs(5, 9, "FD " << fd << " bit set for reading");
 
-            assert(FD_ISSET(fd, &readfds));
+            assert(__WSAFDIsSet(fd_table[fd].win32.handle, readfds));
 
 #endif
 
@@ -562,20 +519,13 @@ comm_select(int msec)
             }
 
             F = &fd_table[fd];
-            debug(5, 6) ("comm_select: FD %d ready for reading\n", fd);
+            debugs(5, 6, "comm_select: FD " << fd << " ready for reading");
 
             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;
+                F->flags.read_pending = 0;
                 commUpdateReadBits(fd, NULL);
                 hdl(fd, F->read_data);
                 statCounter.select_fds++;
@@ -633,9 +583,9 @@ comm_select(int msec)
 
 #if DEBUG_FDBITS
 
-            debug(5, 9) ("FD %d bit set for writing\n", fd);
+            debugs(5, 9, "FD " << fd << " bit set for writing");
 
-            assert(FD_ISSET(fd, &writefds));
+            assert(__WSAFDIsSet(fd_table[fd].win32.handle, writefds));
 
 #endif
 
@@ -655,7 +605,7 @@ comm_select(int msec)
             }
 
             F = &fd_table[fd];
-            debug(5, 5) ("comm_select: FD %d ready for writing\n", fd);
+            debugs(5, 5, "comm_select: FD " << fd << " ready for writing");
 
             if ((hdl = F->write_handler)) {
                 F->write_handler = NULL;
@@ -671,8 +621,6 @@ comm_select(int msec)
 
                 if (commCheckHTTPIncoming)
                     comm_select_http_incoming();
-
-
             }
         }
 
@@ -685,39 +633,13 @@ comm_select(int msec)
         if (callhttp)
             comm_select_http_incoming();
 
-#if DELAY_POOLS
-
-        while ((fd = commGetSlowFd()) != -1) {
-            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;
-                commUpdateReadBits(fd, NULL);
-                hdl(fd, F->read_data);
-                statCounter.select_fds++;
-
-                if (commCheckICPIncoming)
-                    comm_select_icp_incoming();
-
-                if (commCheckDNSIncoming)
-                    comm_select_dns_incoming();
-
-                if (commCheckHTTPIncoming)
-                    comm_select_http_incoming();
-            }
-        }
-
-#endif
         getCurrentTime();
 
         statCounter.select_time += (current_dtime - start);
 
         return COMM_OK;
-    } while (timeout > current_dtime)
-
-        ;
-    debug(5, 8) ("comm_select: time out: %d\n", (int) squid_curtime);
+    } while (timeout > current_dtime);
+    debugs(5, 8, "comm_select: time out: " << squid_curtime);
 
     return COMM_TIMEOUT;
 }
@@ -754,6 +676,15 @@ comm_select_dns_incoming(void)
     statHistCount(&statCounter.comm_dns_incoming, nevents);
 }
 
+static void
+commSelectRegisterWithCacheManager(void)
+{
+    CacheManager::GetInstance()->
+    registerAction("comm_select_incoming",
+                   "comm_incoming() stats",
+                   commIncomingStats, 0, 1);
+}
+
 void
 comm_select_init(void)
 {
@@ -762,14 +693,8 @@ comm_select_init(void)
     FD_ZERO(&global_readfds);
     FD_ZERO(&global_writefds);
     nreadfds = nwritefds = 0;
-}
 
-void
-commSelectRegisterWithCacheManager(CacheManager & manager)
-{
-    manager.registerAction("comm_select_incoming",
-                           "comm_incoming() stats",
-                           commIncomingStats, 0, 1);
+    commSelectRegisterWithCacheManager();
 }
 
 /*
@@ -779,7 +704,7 @@ commSelectRegisterWithCacheManager(CacheManager & manager)
  * and the server side of a cache fetch simultaneoulsy abort the
  * connection.  While I haven't really studied the code to figure out how
  * it happens, the snippet below may prevent the cache from exitting:
- * 
+ *
  * Call this from where the select loop fails.
  */
 static int
@@ -790,57 +715,50 @@ examine_select(fd_set * readfds, fd_set * writefds)
     fd_set write_x;
 
     struct timeval tv;
-    close_handler *ch = NULL;
+    AsyncCall::Pointer ch = NULL;
     fde *F = NULL;
 
     struct stat sb;
-    debug(5, 0) ("examine_select: Examining open file descriptors...\n");
+    debugs(5, 0, "examine_select: Examining open file descriptors...");
 
     for (fd = 0; fd < Squid_MaxFD; fd++) {
         FD_ZERO(&read_x);
         FD_ZERO(&write_x);
         tv.tv_sec = tv.tv_usec = 0;
 
-        if (FD_ISSET(fd, readfds))
+        if (__WSAFDIsSet(fd_table[fd].win32.handle, readfds))
             FD_SET(fd, &read_x);
-        else if (FD_ISSET(fd, writefds))
+        else if (__WSAFDIsSet(fd_table[fd].win32.handle, writefds))
             FD_SET(fd, &write_x);
         else
             continue;
 
         statCounter.syscalls.selects++;
-
         errno = 0;
 
         if (!fstat(fd, &sb)) {
-            debug(5, 5) ("FD %d is valid.\n", fd);
+            debugs(5, 5, "FD " << fd << " is valid.");
             continue;
         }
 
         F = &fd_table[fd];
-        debug(5, 0) ("FD %d: %s\n", fd, xstrerror());
-        debug(5, 0) ("WARNING: FD %d has handlers, but it's invalid.\n", fd);
-        debug(5, 0) ("FD %d is a %s called '%s'\n",
-                     fd,
-                     fdTypeStr[F->type],
-                     F->desc);
-        debug(5, 0) ("tmout:%p read:%p write:%p\n",
-                     F->timeout_handler,
-                     F->read_handler,
-                     F->write_handler);
-
-        for (ch = F->closeHandler; ch; ch = ch->next)
-            debug(5, 0) (" close handler: %p\n", ch->handler);
-
-        if (F->closeHandler) {
+        debugs(5, 0, "FD " << fd << ": " << xstrerror());
+        debugs(5, 0, "WARNING: FD " << fd << " has handlers, but it's invalid.");
+        debugs(5, 0, "FD " << fd << " is a " << fdTypeStr[F->type] << " called '" << F->desc << "'");
+        debugs(5, 0, "tmout:" << F->timeoutHandler << " read:" << F->read_handler << " write:" << F->write_handler);
+
+        for (ch = F->closeHandler; ch != NULL; ch = ch->Next())
+            debugs(5, 0, " close handler: " << ch);
+
+        if (F->closeHandler != NULL) {
             commCallCloseHandlers(fd);
-        } else if (F->timeout_handler) {
-            debug(5, 0) ("examine_select: Calling Timeout Handler\n");
-            F->timeout_handler(fd, F->timeout_data);
+        } else if (F->timeoutHandler != NULL) {
+            debugs(5, 0, "examine_select: Calling Timeout Handler");
+            ScheduleCallHere(F->timeoutHandler);
         }
 
         F->closeHandler = NULL;
-        F->timeout_handler = NULL;
+        F->timeoutHandler = NULL;
         F->read_handler = NULL;
         F->write_handler = NULL;
         FD_CLR(fd, readfds);
@@ -874,10 +792,10 @@ commIncomingStats(StoreEntry * sentry)
 void
 commUpdateReadBits(int fd, PF * handler)
 {
-    if (handler && !FD_ISSET(fd, &global_readfds)) {
+    if (handler && !__WSAFDIsSet(fd_table[fd].win32.handle, &global_readfds)) {
         FD_SET(fd, &global_readfds);
         nreadfds++;
-    } else if (!handler && FD_ISSET(fd, &global_readfds)) {
+    } else if (!handler && __WSAFDIsSet(fd_table[fd].win32.handle, &global_readfds)) {
         FD_CLR(fd, &global_readfds);
         nreadfds--;
     }
@@ -886,10 +804,10 @@ commUpdateReadBits(int fd, PF * handler)
 void
 commUpdateWriteBits(int fd, PF * handler)
 {
-    if (handler && !FD_ISSET(fd, &global_writefds)) {
+    if (handler && !__WSAFDIsSet(fd_table[fd].win32.handle, &global_writefds)) {
         FD_SET(fd, &global_writefds);
         nwritefds++;
-    } else if (!handler && FD_ISSET(fd, &global_writefds)) {
+    } else if (!handler && __WSAFDIsSet(fd_table[fd].win32.handle, &global_writefds)) {
         FD_CLR(fd, &global_writefds);
         nwritefds--;
     }