]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make comm_listen/comm_accept .. optimistic.
authoradrian <>
Wed, 23 Oct 2002 16:11:03 +0000 (16:11 +0000)
committeradrian <>
Wed, 23 Oct 2002 16:11:03 +0000 (16:11 +0000)
When we have an accept event we accept as many times as we can
(up until a #define'd limit) - if the callback doesn't re-register
we don't continue calling it :)

src/comm.cc

index 0ce58c179bcc68e77d6ccdc68f5a28dc5d769e9f..c0bad1859a8111acba546b2187e8d66b2186a387 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.349 2002/10/23 09:17:34 adrian Exp $
+ * $Id: comm.cc,v 1.350 2002/10/23 10:11:03 adrian Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
 #include <netinet/tcp.h>
 #endif
 
+/*
+ * This magic determines how many times to call accept()
+ * at a go.
+ */
+#define        MAX_ACCEPT_PER_LOOP             10
+
 typedef struct {
     char *host;
     u_short port;
@@ -1736,36 +1742,42 @@ comm_accept_try(int fd, void *data)
 {
        int newfd;
        fdc_t *Fc;
+       int count;
+       IOACB *hdl;
 
        assert(fdc_table[fd].active == 1);
 
        Fc = &(fdc_table[fd]);
 
-       /* Accept a new connection */
-       newfd = comm_old_accept(fd, &Fc->accept.pn, &Fc->accept.me);
-
-       if (newfd < 0) {
-               /* Issues - check them */
-               if (newfd == COMM_NOMESSAGE) {
-                       /* register interest again */
-                       commSetSelect(fd, COMM_SELECT_READ, comm_accept_try, NULL, 0);
+       /* XXX magic number! */
+       for (count = 0; count < MAX_ACCEPT_PER_LOOP; count++) {
+               /* Accept a new connection */
+               newfd = comm_old_accept(fd, &Fc->accept.pn, &Fc->accept.me);
+
+                       if (newfd < 0) {
+                       /* Issues - check them */
+                       if (newfd == COMM_NOMESSAGE) {
+                               /* register interest again */
+                               commSetSelect(fd, COMM_SELECT_READ, comm_accept_try, NULL, 0);
+                               return;
+                       }
+                       /* Problem! */
+                       comm_addacceptcallback(fd, -1, Fc->accept.handler, &Fc->accept.pn,
+                           &Fc->accept.me, COMM_ERROR, errno, Fc->accept.handler_data);
+                       Fc->accept.handler = NULL;
+                       Fc->accept.handler_data = NULL;
                        return;
                }
-               /* Problem! */
-               comm_addacceptcallback(fd, -1, Fc->accept.handler, &Fc->accept.pn, &Fc->accept.me, COMM_ERROR, errno, Fc->accept.handler_data);
-               Fc->accept.handler = NULL;
-               Fc->accept.handler_data = NULL;
-               return;
-       }
-
-       /* setup our new filedescriptor in fd_table */
-       /* and set it up in fdc_table */
 
-       /* queue a completed callback with the new FD */
-        comm_addacceptcallback(fd, newfd, Fc->accept.handler, &Fc->accept.pn, &Fc->accept.me, COMM_OK, 0, Fc->accept.handler_data);
-       Fc->accept.handler = NULL;
-       Fc->accept.handler_data = NULL;
+               /* Try the callback! */
+               hdl = Fc->accept.handler;
+               Fc->accept.handler = NULL;
+               hdl(fd, newfd, &Fc->accept.pn, &Fc->accept.me, COMM_OK, 0, Fc->accept.handler_data);
 
+               /* If we weren't re-registed, don't bother trying again! */
+               if (Fc->accept.handler == NULL)
+                       return;
+       }
 }