[PATCH] Core: handle getsockopt(TCP_FASTOPEN) failures.

Piotr Sikora piotr at cloudflare.com
Thu Jan 30 23:06:12 UTC 2014


# HG changeset patch
# User Piotr Sikora <piotr at cloudflare.com>
# Date 1391122701 28800
#      Thu Jan 30 14:58:21 2014 -0800
# Node ID a2abc0e037c87626b30341014d8a35c36adf8f8f
# Parent  2e40188f83ef5bf1ae5afe0dd445689049f46a5c
Core: handle getsockopt(TCP_FASTOPEN) failures.

Linux returns EOPNOTSUPP for non-TCP sockets and ENOPROTOOPT for TCP
sockets, because getsockopt(TCP_FASTOPEN) is not implemented so far.

While there, lower the log level from ALERT to NOTICE to match other
getsockopt() failures.

Signed-off-by: Piotr Sikora <piotr at cloudflare.com>

diff -r 2e40188f83ef -r a2abc0e037c8 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/core/ngx_connection.c Thu Jan 30 14:58:21 2014 -0800
@@ -97,7 +97,7 @@ ngx_set_inherited_sockets(ngx_cycle_t *c
     ngx_uint_t                 i;
     ngx_listening_t           *ls;
     socklen_t                  olen;
-#if (NGX_HAVE_DEFERRED_ACCEPT)
+#if (NGX_HAVE_DEFERRED_ACCEPT || NGX_HAVE_TCP_FASTOPEN)
     ngx_err_t                  err;
 #endif
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
@@ -223,9 +223,13 @@ ngx_set_inherited_sockets(ngx_cycle_t *c
                        (void *) &ls[i].fastopen, &olen)
             == -1)
         {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
-                          "getsockopt(TCP_FASTOPEN) %V failed, ignored",
-                          &ls[i].addr_text);
+            err = ngx_socket_errno;
+
+            if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT) {
+                ngx_log_error(NGX_LOG_NOTICE, cycle->log, err,
+                              "getsockopt(TCP_FASTOPEN) %V failed, ignored",
+                              &ls[i].addr_text);
+            }

             ls[i].fastopen = -1;
         }
diff -r 2e40188f83ef -r a2abc0e037c8 src/os/unix/ngx_errno.h
--- a/src/os/unix/ngx_errno.h Thu Jan 30 19:13:12 2014 +0400
+++ b/src/os/unix/ngx_errno.h Thu Jan 30 14:58:21 2014 -0800
@@ -34,6 +34,7 @@ typedef int               ngx_err_t;
 #define NGX_ENOSPC        ENOSPC
 #define NGX_EPIPE         EPIPE
 #define NGX_EINPROGRESS   EINPROGRESS
+#define NGX_ENOPROTOOPT   ENOPROTOOPT
 #define NGX_EOPNOTSUPP    EOPNOTSUPP
 #define NGX_EADDRINUSE    EADDRINUSE
 #define NGX_ECONNABORTED  ECONNABORTED
diff -r 2e40188f83ef -r a2abc0e037c8 src/os/win32/ngx_errno.h
--- a/src/os/win32/ngx_errno.h Thu Jan 30 19:13:12 2014 +0400
+++ b/src/os/win32/ngx_errno.h Thu Jan 30 14:58:21 2014 -0800
@@ -38,6 +38,7 @@ typedef DWORD                      ngx_e
 #define NGX_EPIPE                  EPIPE
 #define NGX_EAGAIN                 WSAEWOULDBLOCK
 #define NGX_EINPROGRESS            WSAEINPROGRESS
+#define NGX_ENOPROTOOPT            WSAENOPROTOOPT
 #define NGX_EOPNOTSUPP             WSAEOPNOTSUPP
 #define NGX_EADDRINUSE             WSAEADDRINUSE
 #define NGX_ECONNABORTED           WSAECONNABORTED



More information about the nginx-devel mailing list