From: hno <> Date: Fri, 21 Sep 2007 21:16:42 +0000 (+0000) Subject: Add support for Linux TCP_ACCEPT_DEFER accept_filter X-Git-Tag: SQUID_3_0_RC1~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b4d4be53e2ce39f42c28685b5f00e5b7b84dfb4;p=thirdparty%2Fsquid.git Add support for Linux TCP_ACCEPT_DEFER accept_filter --- diff --git a/src/cf.data.pre b/src/cf.data.pre index dc33ed421b..0c1afa02ff 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.471 2007/09/19 21:42:16 hno Exp $ +# $Id: cf.data.pre,v 1.472 2007/09/21 15:16:42 hno Exp $ # # SQUID Web Proxy Cache http://www.squid-cache.org/ # ---------------------------------------------------------- @@ -4552,21 +4552,36 @@ DOC_START DOC_END NAME: accept_filter -IFDEF: SO_ACCEPTFILTER TYPE: string DEFAULT: none LOC: Config.accept_filter DOC_START + FreeBSD: + The name of an accept(2) filter to install on Squid's listen socket(s). This feature is perhaps specific to FreeBSD and requires support in the kernel. The 'httpready' filter delays delivering new connections to Squid until a full HTTP request has been received. - See the accf_http(9) man page. - + See the accf_http(9) man page for details. + + The 'dataready' filter delays delivering new connections + to Squid until there is some data to process. + See the accf_dataready(9) man page for details. + + Linux: + + The 'data' filter delays delivering of new connections + to Squid until there is some data to process by TCP_ACCEPT_DEFER. + You may optionally specify a number of seconds to wait by + 'data=N' where N is the number of seconds. Defaults to 30 + if not specified. See the tcp(7) man page for details. EXAMPLE: +# FreeBSD accept_filter httpready +# Linux +accept_filter data DOC_END NAME: tcp_recv_bufsize diff --git a/src/comm.cc b/src/comm.cc index 11d98d7df6..acd65448fb 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.435 2007/08/24 17:56:45 hno Exp $ + * $Id: comm.cc,v 1.436 2007/09/21 15:16:42 hno Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -2056,8 +2056,8 @@ comm_listen(int sock) { return x; } + if (Config.accept_filter && strcmp(Config.accept_filter, "none") != 0) { #ifdef SO_ACCEPTFILTER - if (Config.accept_filter) { struct accept_filter_arg afa; bzero(&afa, sizeof(afa)); debug(5, 0) ("Installing accept filter '%s' on FD %d\n", @@ -2065,9 +2065,18 @@ comm_listen(int sock) { xstrncpy(afa.af_name, Config.accept_filter, sizeof(afa.af_name)); x = setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa)); if (x < 0) - debug(5, 0) ("SO_ACCEPTFILTER '%s': %s\n", Config.accept_filter, xstrerror()); - } + debugs(5, 0, "SO_ACCEPTFILTER '" << Config.accept_filter << "': '" << xstrerror()); +#elif defined(TCP_DEFER_ACCEPT) + int seconds = 30; + if (strncmp(Config.accept_filter, "data=", 5) == 0) + seconds = atoi(Config.accept_filter + 5); + x = setsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, &seconds, sizeof(seconds)); + if (x < 0) + debugs(5, 0, "TCP_DEFER_ACCEPT '" << Config.accept_filter << "': '" << xstrerror()); +#else + debugs(5, 0, "accept_filter not supported on your OS"); #endif + } return sock; } diff --git a/src/structs.h b/src/structs.h index 73bc70263b..ffc1846c89 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.563 2007/09/01 13:09:59 hno Exp $ + * $Id: structs.h,v 1.564 2007/09/21 15:16:42 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -738,9 +738,7 @@ struct _SquidConfig ssl_client; #endif -#ifdef SO_ACCEPTFILTER char *accept_filter; -#endif }; struct _SquidConfig2