Skip to content

Commit a26b009

Browse files
committed
Merge r1927885, r1927916, r1928022 from trunk:
Make the value set for the socket option TCP_DEFER_ACCEPT configurable * include/ap_listen.h: - Add prototype for ap_set_listentcpdeferaccept - 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 * Follow up to r1927885: Use correct configuration variable. Thanks to @ylavic for finding this. * Follow up to r1927885: Changelog entry and documentation Reviewed by: rpluem, jorton, covener Github: closes #555 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1929574 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5b4ba1e commit a26b009

File tree

6 files changed

+62
-13
lines changed

6 files changed

+62
-13
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-*- coding: utf-8 -*-
22
Changes with Apache 2.4.66
33

4+
*) mpm_common: Add new ListenTCPDeferAccept directive that allows to specify
5+
the value set for the TCP_DEFER_ACCEPT socket option on listen sockets.
6+
[Ruediger Pluem]
7+
48
*) mod_ssl: Add SSLVHostSNIPolicy directive to control the virtual
59
host compatibility policy. PR 69743. [Joe Orton]
610

STATUS

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
175175
2.4.x patch: svn merge -c 1927792 ^/httpd/httpd/trunk .
176176
+1: icing, rpluem, jorton
177177

178-
*) mpm_common: Add new ListenTCPDeferAccept directive that allows to specify
179-
the value set for the TCP_DEFER_ACCEPT socket option on listen sockets.
180-
Trunk version of patch:
181-
https://svn.apache.org/r1927885
182-
https://svn.apache.org/r1927916
183-
https://svn.apache.org/r1928022
184-
Backport version for 2.4.x of patch:
185-
https://patch-diff.githubusercontent.com/raw/apache/httpd/pull/555.diff
186-
Can be applied via apply_backport_pr.sh 555
187-
+1: rpluem, jorton, covener
188-
189178
*) mod_http2: Fix handling of 304 responses from mod_cache. PR 69580.
190179
Trunk version of patch:
191180
https://svn.apache.org/r1924267

docs/manual/mod/mpm_common.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,29 @@ in *BSDs.</compatibility>
363363
</usage>
364364
</directivesynopsis>
365365

366+
<directivesynopsis>
367+
<name>ListenTCPDeferAccept</name>
368+
<description>Value set for the socket option TCP_DEFER_ACCEPT if it is set</description>
369+
<syntax>ListenTCPDeferAccept <var>integer</var></syntax>
370+
<default>ListenTCPDeferAccept 30</default>
371+
<contextlist><context>server config</context></contextlist>
372+
<modulelist><module>event</module><module>worker</module>
373+
<module>prefork</module>
374+
</modulelist>
375+
<compatibility>Available in Apache HTTP Server 2.5.1 and later</compatibility>
376+
377+
<usage>
378+
<p>The value specified here is set as a value for the socket option
379+
<code>TCP_DEFER_ACCEPT</code> if it is set on the listen socket.
380+
This happens when running on Linux and <directive
381+
module="core">AcceptFilter</directive> is set to anything besides
382+
<code>none</code>. In any other cases this setting is ignored.
383+
For more details see the Linux
384+
<a href="http://man7.org/linux/man-pages/man7/tcp.7.html">
385+
tcp(7)</a> man page.</p>
386+
</usage>
387+
</directivesynopsis>
388+
366389
<directivesynopsis>
367390
<name>MaxRequestWorkers</name>
368391
<description>Maximum number of connections that will be processed

include/ap_listen.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ AP_DECLARE_NONSTD(int) ap_close_selected_listeners(ap_slave_t *);
135135
* called.
136136
*/
137137
AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg);
138+
AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd, void *dummy, const char *arg);
138139
AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg);
139140
AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
140141
int argc, char *const argv[]);
@@ -163,7 +164,9 @@ AP_INIT_TAKE_ARGV("Listen", ap_set_listener, NULL, RSRC_CONF, \
163164
AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
164165
"Send buffer size in bytes"), \
165166
AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
166-
RSRC_CONF, "Receive buffer size in bytes")
167+
RSRC_CONF, "Receive buffer size in bytes"), \
168+
AP_INIT_TAKE1("ListenTCPDeferAccept", ap_set_listentcpdeferaccept, NULL, RSRC_CONF, \
169+
"Value set for the socket option TCP_DEFER_ACCEPT if it is set")
167170

168171
#ifdef __cplusplus
169172
}

include/mpm_common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ extern "C" {
6363
#define DEFAULT_LISTENBACKLOG 511
6464
#endif
6565

66+
/*
67+
* Define the default value set for the socket option TCP_DEFER_ACCEPT
68+
* if it is set.
69+
*/
70+
#ifndef DEFAULT_TCP_DEFER_ACCEPT
71+
#define DEFAULT_TCP_DEFER_ACCEPT 30
72+
#endif
73+
6674
/* Signal used to gracefully restart */
6775
#define AP_SIG_GRACEFUL SIGUSR1
6876

server/listen.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ AP_DECLARE_DATA int ap_have_so_reuseport = -1;
5757

5858
static ap_listen_rec *old_listeners;
5959
static int ap_listenbacklog;
60+
static int ap_listentcpdeferaccept;
6061
static int ap_listencbratio;
6162
static int send_buffer_size;
6263
static int receive_buffer_size;
@@ -268,7 +269,7 @@ static void ap_apply_accept_filter(apr_pool_t *p, ap_listen_rec *lis,
268269
accf);
269270
}
270271
#else
271-
rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, 30);
272+
rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, ap_listentcpdeferaccept);
272273
if (rv != APR_SUCCESS && !APR_STATUS_IS_ENOTIMPL(rv)) {
273274
ap_log_perror(APLOG_MARK, APLOG_WARNING, rv, p, APLOGNO(00076)
274275
"Failed to enable APR_TCP_DEFER_ACCEPT");
@@ -947,6 +948,7 @@ AP_DECLARE(void) ap_listen_pre_config(void)
947948
ap_listen_buckets = NULL;
948949
ap_num_listen_buckets = 0;
949950
ap_listenbacklog = DEFAULT_LISTENBACKLOG;
951+
ap_listentcpdeferaccept = DEFAULT_TCP_DEFER_ACCEPT;
950952
ap_listencbratio = 0;
951953

952954
/* Check once whether or not SO_REUSEPORT is supported. */
@@ -1076,6 +1078,26 @@ AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd,
10761078
return NULL;
10771079
}
10781080

1081+
AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd,
1082+
void *dummy,
1083+
const char *arg)
1084+
{
1085+
int b;
1086+
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1087+
1088+
if (err != NULL) {
1089+
return err;
1090+
}
1091+
1092+
b = atoi(arg);
1093+
if (b < 1) {
1094+
return "ListenTCPDeferAccept must be > 0";
1095+
}
1096+
1097+
ap_listentcpdeferaccept = b;
1098+
return NULL;
1099+
}
1100+
10791101
AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd,
10801102
void *dummy,
10811103
const char *arg)

0 commit comments

Comments
 (0)