]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add support for Linux TCP_ACCEPT_DEFER accept_filter
authorhno <>
Fri, 21 Sep 2007 21:16:42 +0000 (21:16 +0000)
committerhno <>
Fri, 21 Sep 2007 21:16:42 +0000 (21:16 +0000)
src/cf.data.pre
src/comm.cc
src/structs.h

index dc33ed421b64f02e2233f8f4d71b9462b043555c..0c1afa02ffc4f859fd0c258c0ce9cb62b32ece25 100644 (file)
@@ -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
index 11d98d7df65826bc452c33a2b2de0bb314286787..acd65448fbeebb76b2e046303cfd3131c88ddbfe 100644 (file)
@@ -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;
 }
index 73bc70263b99e03f6e75d638638a418eebd18e9e..ffc1846c89508e2195644af31f564ff368c92e2c 100644 (file)
@@ -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