From: adrian <> Date: Wed, 23 Oct 2002 16:11:03 +0000 (+0000) Subject: Make comm_listen/comm_accept .. optimistic. X-Git-Tag: SQUID_3_0_PRE1~577 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f49a8979284586a3df00549d705bca8c6817d81b;p=thirdparty%2Fsquid.git Make comm_listen/comm_accept .. optimistic. 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 :) --- diff --git a/src/comm.cc b/src/comm.cc index 0ce58c179b..c0bad1859a 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -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 @@ -44,6 +44,12 @@ #include #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; + } }