--------------------- PatchSet 7105 Date: 2005/10/13 09:14:35 Author: adri Branch: tidyup_deferred_reads Tag: (none) Log: An evil reworking of the half-closed connection support stuff. The half-closed connection stuff now 'defers' the IO read handler until some time in the future, checked in the commCheckTimeouts() loop. The read handler/callback data is squirreled away and restored if the defer timer times out. In essence, its basically a second FD timeout. The logic for deferring read IO until a fixed point in the future is now in the comm layer rather than the client side. This is slightly different from removing the server-side deferred reads but is similar enough to warrant looking at to see if some duplication can be removed whilst preserving the comm/store code separation. Members: src/client_side.c:1.47.2.59.4.2->1.47.2.59.4.3 src/comm.c:1.18.6.5.6.3->1.18.6.5.6.4 src/comm_select.c:1.8.6.6->1.8.6.6.24.1 src/fd.c:1.7.12.1->1.7.12.1.18.1 src/protos.h:1.41.6.22.6.4->1.41.6.22.6.5 src/stat.c:1.13.6.11.6.2->1.13.6.11.6.3 src/structs.h:1.48.2.34.4.7->1.48.2.34.4.8 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.47.2.59.4.2 retrieving revision 1.47.2.59.4.3 diff -u -r1.47.2.59.4.2 -r1.47.2.59.4.3 --- squid/src/client_side.c 12 Oct 2005 08:19:14 -0000 1.47.2.59.4.2 +++ squid/src/client_side.c 13 Oct 2005 09:14:35 -0000 1.47.2.59.4.3 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.47.2.59.4.2 2005/10/12 08:19:14 adri Exp $ + * $Id: client_side.c,v 1.47.2.59.4.3 2005/10/13 09:14:35 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -2959,28 +2959,25 @@ if (conn->body.size_left && !F->flags.socket_eof) return conn->in.offset >= conn->in.size - 1; else - return conn->defer.until > squid_curtime; + return 0; } static void clientDefer(int fd, ConnStateData *conn) { - fd_table[fd].flags.socket_eof = 1; - conn->defer.until = squid_curtime + 1; - conn->defer.n++; - fd_note(fd, "half-closed"); + commHalfClose(fd, 1, clientReadRequest, conn); } static void clientDeferLots(int fd, ConnStateData *conn) { - conn->defer.until = squid_curtime + 100; /* Reset when a request is complete */ + commDeferReadUntil(fd, 100, clientReadRequest, conn); } static void clientFinishDefer(int fd, ConnStateData *conn) { - conn->defer.until = 0; /* Kick it to read a new request */ + commUnHalfClose(fd); } static void Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.18.6.5.6.3 retrieving revision 1.18.6.5.6.4 diff -u -r1.18.6.5.6.3 -r1.18.6.5.6.4 --- squid/src/comm.c 27 Sep 2005 08:10:16 -0000 1.18.6.5.6.3 +++ squid/src/comm.c 13 Oct 2005 09:14:35 -0000 1.18.6.5.6.4 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.18.6.5.6.3 2005/09/27 08:10:16 adri Exp $ + * $Id: comm.c,v 1.18.6.5.6.4 2005/10/13 09:14:35 adri Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1098,3 +1098,47 @@ } } } + +/* + * Read half-close and defer related crack + */ +void +commHalfClose(int fd, int time, PF *handler, void *data) +{ + commDeferReadUntil(fd, time, handler, data); + fd_table[fd].defer.n++; + fd_table[fd].flags.socket_eof = 1; + fd_note(fd, "half-closed"); +} + +void +commDeferReadUntil(int fd, int time, PF *handler, void *data) +{ + fd_table[fd].defer.read_handler = handler; + fd_table[fd].defer.read_data = data; + fd_table[fd].defer.until = squid_curtime + time; + commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); +} + +void +commUnHalfClose(int fd) +{ + fd_table[fd].defer.until = 0; + fd_table[fd].flags.socket_eof = 0; + commSetSelect(fd, COMM_SELECT_READ, fd_table[fd].defer.read_handler, + fd_table[fd].defer.read_data, 0); + fd_table[fd].defer.read_handler = NULL; + fd_table[fd].defer.read_data = NULL; +} + +void +commCheckHalfClose(int fd) +{ + if (fd_table[fd].defer.until == 0) { + return; + } + if (fd_table[fd].defer.until < squid_curtime) { + commUnHalfClose(fd); + return; + } +} Index: squid/src/comm_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_select.c,v retrieving revision 1.8.6.6 retrieving revision 1.8.6.6.24.1 diff -u -r1.8.6.6 -r1.8.6.6.24.1 --- squid/src/comm_select.c 12 May 2003 02:14:21 -0000 1.8.6.6 +++ squid/src/comm_select.c 13 Oct 2005 09:14:35 -0000 1.8.6.6.24.1 @@ -1,6 +1,6 @@ /* - * $Id: comm_select.c,v 1.8.6.6 2003/05/12 02:14:21 squidadm Exp $ + * $Id: comm_select.c,v 1.8.6.6.24.1 2005/10/13 09:14:35 adri Exp $ * * DEBUG: section 5 Socket Functions * @@ -1033,6 +1033,12 @@ F = &fd_table[fd]; if (!F->flags.open) continue; + /* re-kick read IO if we care about it */ + /* + * Note: this may register an IO and then have it cancelled below. + * It shouldn't be a problem, it just may be inefficient. + */ + commCheckHalfClose(fd); if (F->timeout == 0) continue; if (F->timeout > squid_curtime) Index: squid/src/fd.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fd.c,v retrieving revision 1.7.12.1 retrieving revision 1.7.12.1.18.1 diff -u -r1.7.12.1 -r1.7.12.1.18.1 --- squid/src/fd.c 15 Dec 2003 03:13:47 -0000 1.7.12.1 +++ squid/src/fd.c 13 Oct 2005 09:14:35 -0000 1.7.12.1.18.1 @@ -1,6 +1,6 @@ /* - * $Id: fd.c,v 1.7.12.1 2003/12/15 03:13:47 squidadm Exp $ + * $Id: fd.c,v 1.7.12.1.18.1 2005/10/13 09:14:35 adri Exp $ * * DEBUG: section 51 Filedescriptor Functions * AUTHOR: Duane Wessels @@ -121,6 +121,10 @@ F->flags.open = 1; F->read_method = &default_read_method; F->write_method = &default_write_method; + F->defer.n = 0; + F->defer.until = 0; + F->defer.read_handler = NULL; + F->defer.read_data = NULL; fdUpdateBiggest(fd, 1); if (desc) xstrncpy(F->desc, desc, FD_DESC_SZ); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.41.6.22.6.4 retrieving revision 1.41.6.22.6.5 diff -u -r1.41.6.22.6.4 -r1.41.6.22.6.5 --- squid/src/protos.h 12 Oct 2005 07:53:33 -0000 1.41.6.22.6.4 +++ squid/src/protos.h 13 Oct 2005 09:14:35 -0000 1.41.6.22.6.5 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.41.6.22.6.4 2005/10/12 07:53:33 adri Exp $ + * $Id: protos.h,v 1.41.6.22.6.5 2005/10/13 09:14:35 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -175,6 +175,10 @@ extern void commSetDefer(int fd, DEFER * func, void *); extern int ignoreErrno(int); extern void commCloseAllSockets(void); +extern void commDeferReadUntil(int fd, int time, PF *handler, void *data); +extern void commHalfClose(int fd, int time, PF *handler, void *data); +extern void commUnHalfClose(int fd); +extern void commCheckHalfClose(int fd); /* Index: squid/src/stat.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/stat.c,v retrieving revision 1.13.6.11.6.2 retrieving revision 1.13.6.11.6.3 diff -u -r1.13.6.11.6.2 -r1.13.6.11.6.3 --- squid/src/stat.c 12 Oct 2005 07:53:33 -0000 1.13.6.11.6.2 +++ squid/src/stat.c 13 Oct 2005 09:14:35 -0000 1.13.6.11.6.3 @@ -1,6 +1,6 @@ /* - * $Id: stat.c,v 1.13.6.11.6.2 2005/10/12 07:53:33 adri Exp $ + * $Id: stat.c,v 1.13.6.11.6.3 2005/10/13 09:14:35 adri Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -1462,7 +1462,7 @@ storeAppendPrintf(s, "\tnrequests: %d\n", conn->nrequests); storeAppendPrintf(s, "\tdefer: n %d, until %ld\n", - conn->defer.n, (long int) conn->defer.until); + fd_table[fd].defer.n, (long int) fd_table[fd].defer.until); } storeAppendPrintf(s, "uri %s\n", http->uri); storeAppendPrintf(s, "log_type %s\n", log_tags[http->log_type]); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.48.2.34.4.7 retrieving revision 1.48.2.34.4.8 diff -u -r1.48.2.34.4.7 -r1.48.2.34.4.8 --- squid/src/structs.h 9 Oct 2005 15:47:15 -0000 1.48.2.34.4.7 +++ squid/src/structs.h 13 Oct 2005 09:14:35 -0000 1.48.2.34.4.8 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.48.2.34.4.7 2005/10/09 15:47:15 adri Exp $ + * $Id: structs.h,v 1.48.2.34.4.8 2005/10/13 09:14:35 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -832,6 +832,12 @@ SSL *ssl; int ssl_shutdown:1; #endif + struct { + int until; + PF *read_handler; + void *read_data; + int n; + } defer; }; struct _fileMap { @@ -1149,10 +1155,6 @@ struct in_addr log_addr; char rfc931[USER_IDENT_SZ]; int nrequests; - struct { - int n; - time_t until; - } defer; }; struct _ipcache_addrs {