]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/comm/ModSelect.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / comm / ModSelect.cc
index 699c67cb22284a5a6320742b4d7ae8d3bc60fc01..27ab585dff3b4821ec503796c6a980540dc433f1 100644 (file)
 
 #if USE_SELECT
 
-#include "squid-old.h"
 #include "anyp/PortCfg.h"
 #include "comm/Connection.h"
 #include "comm/Loops.h"
 #include "fde.h"
+#include "globals.h"
 #include "ICP.h"
 #include "mgr/Registration.h"
 #include "SquidTime.h"
 #include "StatHist.h"
 #include "Store.h"
 
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
 static int MAX_POLL_TIME = 1000;       /* see also Comm::QuickPollRequired() */
 
 #ifndef        howmany
@@ -68,7 +75,6 @@ static void comm_select_dns_incoming(void);
 static void commUpdateReadBits(int fd, PF * handler);
 static void commUpdateWriteBits(int fd, PF * handler);
 
-
 static struct timeval zero_tv;
 static fd_set global_readfds;
 static fd_set global_writefds;
@@ -215,7 +221,7 @@ comm_check_incoming_select_handlers(int nfds, int *fds)
     FD_ZERO(&write_mask);
     incoming_sockets_accepted = 0;
 
-    for (i = 0; i < nfds; i++) {
+    for (i = 0; i < nfds; ++i) {
         fd = fds[i];
 
         if (fd_table[fd].read_handler) {
@@ -238,12 +244,12 @@ comm_check_incoming_select_handlers(int nfds, int *fds)
 
     getCurrentTime();
 
-    statCounter.syscalls.selects++;
+    ++ statCounter.syscalls.selects;
 
     if (select(maxfd, &read_mask, &write_mask, NULL, &zero_tv) < 1)
         return incoming_sockets_accepted;
 
-    for (i = 0; i < nfds; i++) {
+    for (i = 0; i < nfds; ++i) {
         fd = fds[i];
 
         if (FD_ISSET(fd, &read_mask)) {
@@ -252,7 +258,7 @@ comm_check_incoming_select_handlers(int nfds, int *fds)
                 commUpdateReadBits(fd, NULL);
                 hdl(fd, fd_table[fd].read_data);
             } else {
-                debugs(5, 1, "comm_select_incoming: FD " << fd << " NULL read handler");
+                debugs(5, DBG_IMPORTANT, "comm_select_incoming: FD " << fd << " NULL read handler");
             }
         }
 
@@ -262,7 +268,7 @@ comm_check_incoming_select_handlers(int nfds, int *fds)
                 commUpdateWriteBits(fd, NULL);
                 hdl(fd, fd_table[fd].write_data);
             } else {
-                debugs(5, 1, "comm_select_incoming: FD " << fd << " NULL write handler");
+                debugs(5, DBG_IMPORTANT, "comm_select_incoming: FD " << fd << " NULL write handler");
             }
         }
     }
@@ -278,11 +284,15 @@ comm_select_udp_incoming(void)
     int nevents;
     udp_io_events = 0;
 
-    if (Comm::IsConnOpen(icpIncomingConn))
-        fds[nfds++] = icpIncomingConn->fd;
+    if (Comm::IsConnOpen(icpIncomingConn)) {
+        fds[nfds] = icpIncomingConn->fd;
+        ++nfds;
+    }
 
-    if (Comm::IsConnOpen(icpOutgoingConn) && icpIncomingConn != icpOutgoingConn)
-        fds[nfds++] = icpOutgoingConn->fd;
+    if (Comm::IsConnOpen(icpOutgoingConn) && icpIncomingConn != icpOutgoingConn) {
+        fds[nfds] = icpOutgoingConn->fd;
+        ++nfds;
+    }
 
     if (nfds == 0)
         return;
@@ -314,8 +324,10 @@ comm_select_tcp_incoming(void)
     // XXX: only poll sockets that won't be deferred. But how do we identify them?
 
     for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) {
-        if (Comm::IsConnOpen(s->listenConn))
-            fds[nfds++] = s->listenConn->fd;
+        if (Comm::IsConnOpen(s->listenConn)) {
+            fds[nfds] = s->listenConn->fd;
+            ++nfds;
+        }
     }
 
     nevents = comm_check_incoming_select_handlers(nfds, fds);
@@ -397,11 +409,11 @@ Comm::DoSelect(int msec)
 
         fdsp = (fd_mask *) & readfds;
 
-        for (j = 0; j < maxindex; j++) {
+        for (j = 0; j < maxindex; ++j) {
             if ((tmask = fdsp[j]) == 0)
                 continue;      /* no bits here */
 
-            for (k = 0; k < FD_MASK_BITS; k++) {
+            for (k = 0; k < FD_MASK_BITS; ++k) {
                 if (!EBIT_TEST(tmask, k))
                     continue;
 
@@ -410,13 +422,13 @@ Comm::DoSelect(int msec)
 
                 if (FD_ISSET(fd, &readfds) && fd_table[fd].flags.read_pending) {
                     FD_SET(fd, &pendingfds);
-                    pending++;
+                    ++pending;
                 }
             }
         }
 
 #if DEBUG_FDBITS
-        for (i = 0; i < maxfd; i++) {
+        for (i = 0; i < maxfd; ++i) {
             /* Check each open socket for a handler. */
 
             if (fd_table[i].read_handler) {
@@ -443,9 +455,9 @@ Comm::DoSelect(int msec)
         for (;;) {
             poll_time.tv_sec = msec / 1000;
             poll_time.tv_usec = (msec % 1000) * 1000;
-            statCounter.syscalls.selects++;
+            ++ statCounter.syscalls.selects;
             num = select(maxfd, &readfds, &writefds, NULL, &poll_time);
-            ++statCounter.select_loops;
+            ++ statCounter.select_loops;
 
             if (num >= 0 || pending > 0)
                 break;
@@ -453,7 +465,7 @@ Comm::DoSelect(int msec)
             if (ignoreErrno(errno))
                 break;
 
-            debugs(5, 0, "comm_select: select failure: " << xstrerror());
+            debugs(5, DBG_CRITICAL, "comm_select: select failure: " << xstrerror());
 
             examine_select(&readfds, &writefds);
 
@@ -481,11 +493,11 @@ Comm::DoSelect(int msec)
 
         maxindex = howmany(maxfd, FD_MASK_BITS);
 
-        for (j = 0; j < maxindex; j++) {
+        for (j = 0; j < maxindex; ++j) {
             if ((tmask = (fdsp[j] | pfdsp[j])) == 0)
                 continue;      /* no bits here */
 
-            for (k = 0; k < FD_MASK_BITS; k++) {
+            for (k = 0; k < FD_MASK_BITS; ++k) {
                 if (tmask == 0)
                     break;     /* no more bits left */
 
@@ -530,7 +542,7 @@ Comm::DoSelect(int msec)
                     F->flags.read_pending = 0;
                     commUpdateReadBits(fd, NULL);
                     hdl(fd, F->read_data);
-                    statCounter.select_fds++;
+                    ++ statCounter.select_fds;
 
                     if (commCheckUdpIncoming)
                         comm_select_udp_incoming();
@@ -546,11 +558,11 @@ Comm::DoSelect(int msec)
 
         fdsp = (fd_mask *) & writefds;
 
-        for (j = 0; j < maxindex; j++) {
+        for (j = 0; j < maxindex; ++j) {
             if ((tmask = fdsp[j]) == 0)
                 continue;      /* no bits here */
 
-            for (k = 0; k < FD_MASK_BITS; k++) {
+            for (k = 0; k < FD_MASK_BITS; ++k) {
                 if (tmask == 0)
                     break;     /* no more bits left */
 
@@ -592,7 +604,7 @@ Comm::DoSelect(int msec)
                     F->write_handler = NULL;
                     commUpdateWriteBits(fd, NULL);
                     hdl(fd, F->write_data);
-                    statCounter.select_fds++;
+                    ++ statCounter.select_fds;
 
                     if (commCheckUdpIncoming)
                         comm_select_udp_incoming();
@@ -637,11 +649,15 @@ comm_select_dns_incoming(void)
     if (DnsSocketA < 0 && DnsSocketB < 0)
         return;
 
-    if (DnsSocketA >= 0)
-        fds[nfds++] = DnsSocketA;
+    if (DnsSocketA >= 0) {
+        fds[nfds] = DnsSocketA;
+        ++nfds;
+    }
 
-    if (DnsSocketB >= 0)
-        fds[nfds++] = DnsSocketB;
+    if (DnsSocketB >= 0) {
+        fds[nfds] = DnsSocketB;
+        ++nfds;
+    }
 
     nevents = comm_check_incoming_select_handlers(nfds, fds);
 
@@ -698,9 +714,9 @@ examine_select(fd_set * readfds, fd_set * writefds)
     fde *F = NULL;
 
     struct stat sb;
-    debugs(5, 0, "examine_select: Examining open file descriptors...");
+    debugs(5, DBG_CRITICAL, "examine_select: Examining open file descriptors...");
 
-    for (fd = 0; fd < Squid_MaxFD; fd++) {
+    for (fd = 0; fd < Squid_MaxFD; ++fd) {
         FD_ZERO(&read_x);
         FD_ZERO(&write_x);
         tv.tv_sec = tv.tv_usec = 0;
@@ -712,7 +728,7 @@ examine_select(fd_set * readfds, fd_set * writefds)
         else
             continue;
 
-        statCounter.syscalls.selects++;
+        ++ statCounter.syscalls.selects;
         errno = 0;
 
         if (!fstat(fd, &sb)) {
@@ -721,18 +737,18 @@ examine_select(fd_set * readfds, fd_set * writefds)
         }
 
         F = &fd_table[fd];
-        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);
+        debugs(5, DBG_CRITICAL, "FD " << fd << ": " << xstrerror());
+        debugs(5, DBG_CRITICAL, "WARNING: FD " << fd << " has handlers, but it's invalid.");
+        debugs(5, DBG_CRITICAL, "FD " << fd << " is a " << fdTypeStr[F->type] << " called '" << F->desc << "'");
+        debugs(5, DBG_CRITICAL, "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);
+            debugs(5, DBG_CRITICAL, " close handler: " << ch);
 
         if (F->closeHandler != NULL) {
             commCallCloseHandlers(fd);
         } else if (F->timeoutHandler != NULL) {
-            debugs(5, 0, "examine_select: Calling Timeout Handler");
+            debugs(5, DBG_CRITICAL, "examine_select: Calling Timeout Handler");
             ScheduleCallHere(F->timeoutHandler);
         }
 
@@ -747,7 +763,6 @@ examine_select(fd_set * readfds, fd_set * writefds)
     return 0;
 }
 
-
 static void
 commIncomingStats(StoreEntry * sentry)
 {
@@ -772,10 +787,10 @@ commUpdateReadBits(int fd, PF * handler)
 {
     if (handler && !FD_ISSET(fd, &global_readfds)) {
         FD_SET(fd, &global_readfds);
-        nreadfds++;
+        ++nreadfds;
     } else if (!handler && FD_ISSET(fd, &global_readfds)) {
         FD_CLR(fd, &global_readfds);
-        nreadfds--;
+        --nreadfds;
     }
 }
 
@@ -784,10 +799,10 @@ commUpdateWriteBits(int fd, PF * handler)
 {
     if (handler && !FD_ISSET(fd, &global_writefds)) {
         FD_SET(fd, &global_writefds);
-        nwritefds++;
+        ++nwritefds;
     } else if (!handler && FD_ISSET(fd, &global_writefds)) {
         FD_CLR(fd, &global_writefds);
-        nwritefds--;
+        --nwritefds;
     }
 }