Skip to content

Commit

Permalink
Stream: the "deferred" parameter of the "listen" directive.
Browse files Browse the repository at this point in the history
The Linux TCP_DEFER_ACCEPT support.
  • Loading branch information
pluknet committed Mar 22, 2024
1 parent f00b431 commit 03eba69
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/stream/ngx_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,10 @@ ngx_stream_add_listening(ngx_conf_t *cf, ngx_stream_conf_addr_t *addr)
ls->keepcnt = addr->opt.tcp_keepcnt;
#endif

#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
ls->deferred_accept = addr->opt.deferred_accept;
#endif

#if (NGX_HAVE_INET6)
ls->ipv6only = addr->opt.ipv6only;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/stream/ngx_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct {
#if (NGX_HAVE_INET6)
unsigned ipv6only:1;
#endif
unsigned deferred_accept:1;
unsigned reuseport:1;
unsigned so_keepalive:2;
unsigned proxy_protocol:1;
Expand Down
19 changes: 19 additions & 0 deletions src/stream/ngx_stream_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,19 @@ ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}

if (ngx_strcmp(value[i].data, "deferred") == 0) {
#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
lsopt.deferred_accept = 1;
lsopt.set = 1;
lsopt.bind = 1;
#else
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"the deferred accept is not supported "
"on this platform, ignored");
#endif
continue;
}

if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) {
#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
if (ngx_strcmp(&value[i].data[10], "n") == 0) {
Expand Down Expand Up @@ -1173,6 +1186,12 @@ ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "\"backlog\" parameter is incompatible with \"udp\"";
}

#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
if (lsopt.deferred_accept) {
return "\"deferred\" parameter is incompatible with \"udp\"";
}
#endif

#if (NGX_STREAM_SSL)
if (lsopt.ssl) {
return "\"ssl\" parameter is incompatible with \"udp\"";
Expand Down

0 comments on commit 03eba69

Please sign in to comment.