]> git.kaiwu.me - nginx.git/commitdiff
Stream: the "deferred" parameter of the "listen" directive.
authorSergey Kandaurov <pluknet@nginx.com>
Fri, 22 Mar 2024 10:53:19 +0000 (14:53 +0400)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 22 Mar 2024 10:53:19 +0000 (14:53 +0400)
The Linux TCP_DEFER_ACCEPT support.

src/stream/ngx_stream.c
src/stream/ngx_stream.h
src/stream/ngx_stream_core_module.c

index 9e16cd382f1920f62b0d037e9d6313e7a79a4157..9a918421311c04aea3bf6acc740229a4a3db9141 100644 (file)
@@ -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
index 3033206da229cce7fe99549b8ea35c6b2382006f..2221a14c943009207221f08c30305ebd5d51be35 100644 (file)
@@ -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;
index 67129b5ed58e1ed7bc5bd16a4d05cd484ccd2978..4bf0784d53acb624e636b2c86c7d33ebeadbcfdb 100644 (file)
@@ -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) {
@@ -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\"";