]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Make the value set for the socket option TCP_DEFER_ACCEPT configurable
authorRuediger Pluem <rpluem@apache.org>
Tue, 19 Aug 2025 12:45:15 +0000 (12:45 +0000)
committerRuediger Pluem <rpluem@apache.org>
Tue, 19 Aug 2025 12:45:15 +0000 (12:45 +0000)
* include/ap_listen.h:
  - Add prototype for include/ap_listen.heraccept
  - Wire in new directive ListenTCPDeferAccept

* include/mpm_common.h:
  Define the previous static value as default value via DEFAULT_TCP_DEFER_ACCEPT

* server/listen.c:
  - Add static int ap_listentcpdeferaccept
  - ap_apply_accept_filter: Use value of ap_listenbacklog for setting TCP_DEFER_ACCEPT
  - ap_listen_pre_config: Set default value
  - Add ap_set_listentcpdeferaccept

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1927885 13f79535-47bb-0310-9956-ffa450edef68

include/ap_listen.h
include/mpm_common.h
server/listen.c

index 87cbc119ddef51e8a046190c1a95a7da85fb2f9e..6aceb466296cf55029c4f276df0af41c2f51dd8e 100644 (file)
@@ -150,6 +150,7 @@ AP_DECLARE_NONSTD(int) ap_close_selected_listeners(ap_slave_t *);
  * called.
  */
 AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg);
+AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd, void *dummy, const char *arg);
 AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg);
 AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
                                                 int argc, char *const argv[]);
@@ -184,7 +185,9 @@ AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
 AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
               RSRC_CONF, "Receive buffer size in bytes"), \
 AP_INIT_FLAG("AcceptErrorsNonFatal", ap_set_accept_errors_nonfatal, NULL, \
-              RSRC_CONF, "Some accept() errors are not fatal to the process")
+              RSRC_CONF, "Some accept() errors are not fatal to the process"), \
+AP_INIT_TAKE1("ListenTCPDeferAccept", ap_set_listentcpdeferaccept, NULL, RSRC_CONF, \
+  "Value set for the socket option TCP_DEFER_ACCEPT if it is set")
 #ifdef __cplusplus
 }
 #endif
index 334624ee065a84721f2da7a804defd10c9f15882..08fc380b86c40155a460eea564d8b171f7124de8 100644 (file)
@@ -63,6 +63,14 @@ extern "C" {
 #define DEFAULT_LISTENBACKLOG 511
 #endif
 
+/*
+ * Define the default value set for the socket option TCP_DEFER_ACCEPT
+ * if it is set.
+ */
+#ifndef DEFAULT_TCP_DEFER_ACCEPT
+#define DEFAULT_TCP_DEFER_ACCEPT 30
+#endif
+
 /* Signal used to gracefully restart */
 #define AP_SIG_GRACEFUL SIGUSR1
 
index 668b627171c597f5a217f536c2bb401d92850b6d..e253ee42b436fa859713eab78ddf90ae37fd5eec 100644 (file)
@@ -60,6 +60,7 @@ AP_DECLARE_DATA int ap_accept_errors_nonfatal = 0;
 
 static ap_listen_rec *old_listeners;
 static int ap_listenbacklog;
+static int ap_listentcpdeferaccept;
 static int ap_listencbratio;
 static int send_buffer_size;
 static int receive_buffer_size;
@@ -287,7 +288,7 @@ static void ap_apply_accept_filter(apr_pool_t *p, ap_listen_rec *lis,
                           accf);
         }
 #else
-        rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, 30);
+        rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, ap_listenbacklog);
         if (rv != APR_SUCCESS && !APR_STATUS_IS_ENOTIMPL(rv)) {
             ap_log_perror(APLOG_MARK, APLOG_WARNING, rv, p, APLOGNO(00076)
                               "Failed to enable APR_TCP_DEFER_ACCEPT");
@@ -986,6 +987,7 @@ AP_DECLARE(void) ap_listen_pre_config(void)
     ap_listen_buckets = NULL;
     ap_num_listen_buckets = 0;
     ap_listenbacklog = DEFAULT_LISTENBACKLOG;
+    ap_listentcpdeferaccept = DEFAULT_TCP_DEFER_ACCEPT;
     ap_listencbratio = 0;
 
     /* Check once whether or not SO_REUSEPORT is supported. */
@@ -1192,6 +1194,26 @@ AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd,
     return NULL;
 }
 
+AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd,
+                                                            void *dummy,
+                                                            const char *arg)
+{
+    int b;
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+    if (err != NULL) {
+        return err;
+    }
+
+    b = atoi(arg);
+    if (b < 1) {
+        return "ListenTCPDeferAccept must be > 0";
+    }
+
+    ap_listentcpdeferaccept = b;
+    return NULL;
+}
+
 AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd,
                                                      void *dummy,
                                                      const char *arg)