From: Ruediger Pluem Date: Tue, 19 Aug 2025 12:45:15 +0000 (+0000) Subject: Make the value set for the socket option TCP_DEFER_ACCEPT configurable X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=713100ca6a88eaf270285f50e56af070bb9feed2;p=thirdparty%2Fapache%2Fhttpd.git Make the value set for the socket option TCP_DEFER_ACCEPT configurable * 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 --- diff --git a/include/ap_listen.h b/include/ap_listen.h index 87cbc119dd..6aceb46629 100644 --- a/include/ap_listen.h +++ b/include/ap_listen.h @@ -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 diff --git a/include/mpm_common.h b/include/mpm_common.h index 334624ee06..08fc380b86 100644 --- a/include/mpm_common.h +++ b/include/mpm_common.h @@ -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 diff --git a/server/listen.c b/server/listen.c index 668b627171..e253ee42b4 100644 --- a/server/listen.c +++ b/server/listen.c @@ -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)