From: Bruno Haible Date: Tue, 24 Apr 2018 18:04:05 +0000 (+0200) Subject: sys_socket: Make SO_REUSEPORT available across platforms. X-Git-Tag: v1.0~5676 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=37efd1c53621f26d935e5fb6d8e49dbe9a4cd8df;p=gnulib.git sys_socket: Make SO_REUSEPORT available across platforms. Reported by Tom G. Christensen . * lib/sys_socket.in.h (SO_REUSEPORT): New macro. * doc/posix-headers/sys_socket.texi: Mention the issue. * tests/test-poll.c (SO_REUSEPORT): Remove. * tests/test-select.h: Include . (SO_REUSEPORT): Remove. * modules/select-tests (Depends-on): Add 'sys_socket'. --- diff --git a/ChangeLog b/ChangeLog index 1c6f322946..9f809cce84 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2018-04-24 Bruno Haible + + sys_socket: Make SO_REUSEPORT available across platforms. + Reported by Tom G. Christensen . + * lib/sys_socket.in.h (SO_REUSEPORT): New macro. + * doc/posix-headers/sys_socket.texi: Mention the issue. + * tests/test-poll.c (SO_REUSEPORT): Remove. + * tests/test-select.h: Include . + (SO_REUSEPORT): Remove. + * modules/select-tests (Depends-on): Add 'sys_socket'. + 2018-04-21 Benno Schulenberg (tiny change) localcharset: short-circuit the search for an alias on a Mac diff --git a/doc/posix-headers/sys_socket.texi b/doc/posix-headers/sys_socket.texi index 380a0ae862..2fa748e7e4 100644 --- a/doc/posix-headers/sys_socket.texi +++ b/doc/posix-headers/sys_socket.texi @@ -32,6 +32,10 @@ AIX 7.1. The @code{CMSG_SPACE} and @code{CMSG_LEN} macros are not provided on some platforms: OpenVMS. +@item +This header file does not define the @code{SO_REUSEPORT} macro on some +platforms: +Minix 3.1.8, Solaris 10, Cygwin, mingw, MSVC 14. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h index 7102588a31..cbaf5cf11c 100644 --- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -215,6 +215,15 @@ struct msghdr { #endif +/* Ensure SO_REUSEPORT is defined. */ +/* For the subtle differences between SO_REUSEPORT and SO_REUSEADDR, see + https://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t + and https://lwn.net/Articles/542629/ + */ +#ifndef SO_REUSEPORT +# define SO_REUSEPORT SO_REUSEADDR +#endif + /* Fix some definitions from . */ #if @HAVE_WINSOCK2_H@ diff --git a/modules/select-tests b/modules/select-tests index bd7b731371..899b50cddf 100644 --- a/modules/select-tests +++ b/modules/select-tests @@ -10,6 +10,7 @@ tests/test-select-stdin.c Depends-on: stdbool +sys_socket netinet_in arpa_inet unistd diff --git a/tests/test-poll.c b/tests/test-poll.c index c5e0a92deb..ebace0f186 100644 --- a/tests/test-poll.c +++ b/tests/test-poll.c @@ -52,10 +52,6 @@ SIGNATURE_CHECK (poll, int, (struct pollfd[], nfds_t, int)); #include #endif -#ifndef SO_REUSEPORT -#define SO_REUSEPORT SO_REUSEADDR -#endif - #define TEST_PORT 12345 diff --git a/tests/test-select.h b/tests/test-select.h index d751e42450..364687b6c5 100644 --- a/tests/test-select.h +++ b/tests/test-select.h @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -37,10 +38,6 @@ # include #endif -#ifndef SO_REUSEPORT -# define SO_REUSEPORT SO_REUSEADDR -#endif - #define TEST_PORT 12345