Skip to content

Commit 713100c

Browse files
committed
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
1 parent b832730 commit 713100c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

include/ap_listen.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ AP_DECLARE_NONSTD(int) ap_close_selected_listeners(ap_slave_t *);
150150
* called.
151151
*/
152152
AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg);
153+
AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd, void *dummy, const char *arg);
153154
AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg);
154155
AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
155156
int argc, char *const argv[]);
@@ -184,7 +185,9 @@ AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
184185
AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
185186
RSRC_CONF, "Receive buffer size in bytes"), \
186187
AP_INIT_FLAG("AcceptErrorsNonFatal", ap_set_accept_errors_nonfatal, NULL, \
187-
RSRC_CONF, "Some accept() errors are not fatal to the process")
188+
RSRC_CONF, "Some accept() errors are not fatal to the process"), \
189+
AP_INIT_TAKE1("ListenTCPDeferAccept", ap_set_listentcpdeferaccept, NULL, RSRC_CONF, \
190+
"Value set for the socket option TCP_DEFER_ACCEPT if it is set")
188191
#ifdef __cplusplus
189192
}
190193
#endif

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
@@ -60,6 +60,7 @@ AP_DECLARE_DATA int ap_accept_errors_nonfatal = 0;
6060

6161
static ap_listen_rec *old_listeners;
6262
static int ap_listenbacklog;
63+
static int ap_listentcpdeferaccept;
6364
static int ap_listencbratio;
6465
static int send_buffer_size;
6566
static int receive_buffer_size;
@@ -287,7 +288,7 @@ static void ap_apply_accept_filter(apr_pool_t *p, ap_listen_rec *lis,
287288
accf);
288289
}
289290
#else
290-
rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, 30);
291+
rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, ap_listenbacklog);
291292
if (rv != APR_SUCCESS && !APR_STATUS_IS_ENOTIMPL(rv)) {
292293
ap_log_perror(APLOG_MARK, APLOG_WARNING, rv, p, APLOGNO(00076)
293294
"Failed to enable APR_TCP_DEFER_ACCEPT");
@@ -986,6 +987,7 @@ AP_DECLARE(void) ap_listen_pre_config(void)
986987
ap_listen_buckets = NULL;
987988
ap_num_listen_buckets = 0;
988989
ap_listenbacklog = DEFAULT_LISTENBACKLOG;
990+
ap_listentcpdeferaccept = DEFAULT_TCP_DEFER_ACCEPT;
989991
ap_listencbratio = 0;
990992

991993
/* Check once whether or not SO_REUSEPORT is supported. */
@@ -1192,6 +1194,26 @@ AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd,
11921194
return NULL;
11931195
}
11941196

1197+
AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd,
1198+
void *dummy,
1199+
const char *arg)
1200+
{
1201+
int b;
1202+
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
1203+
1204+
if (err != NULL) {
1205+
return err;
1206+
}
1207+
1208+
b = atoi(arg);
1209+
if (b < 1) {
1210+
return "ListenTCPDeferAccept must be > 0";
1211+
}
1212+
1213+
ap_listentcpdeferaccept = b;
1214+
return NULL;
1215+
}
1216+
11951217
AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd,
11961218
void *dummy,
11971219
const char *arg)

0 commit comments

Comments
 (0)