changeset 39304:1be4ca580c53

sys_socket: Make SO_REUSEPORT available across platforms. Reported by Tom G. Christensen <tgc@jupiterrise.com>. * 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 <sys/socket.h>. (SO_REUSEPORT): Remove. * modules/select-tests (Depends-on): Add 'sys_socket'.
author Bruno Haible <bruno@clisp.org>
date Tue, 24 Apr 2018 20:04:05 +0200
parents aa7035f1df43
children b6b010b0c3dc
files ChangeLog doc/posix-headers/sys_socket.texi lib/sys_socket.in.h modules/select-tests tests/test-poll.c tests/test-select.h
diffstat 6 files changed, 26 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Apr 24 08:09:57 2018 -0700
+++ b/ChangeLog	Tue Apr 24 20:04:05 2018 +0200
@@ -1,3 +1,14 @@
+2018-04-24  Bruno Haible  <bruno@clisp.org>
+
+	sys_socket: Make SO_REUSEPORT available across platforms.
+	Reported by Tom G. Christensen <tgc@jupiterrise.com>.
+	* 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 <sys/socket.h>.
+	(SO_REUSEPORT): Remove.
+	* modules/select-tests (Depends-on): Add 'sys_socket'.
+
 2018-04-21  Benno Schulenberg  <bensberg@telfort.nl>  (tiny change)
 
 	localcharset: short-circuit the search for an alias on a Mac
--- a/doc/posix-headers/sys_socket.texi	Tue Apr 24 08:09:57 2018 -0700
+++ b/doc/posix-headers/sys_socket.texi	Tue Apr 24 20:04:05 2018 +0200
@@ -32,6 +32,10 @@
 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:
--- a/lib/sys_socket.in.h	Tue Apr 24 08:09:57 2018 -0700
+++ b/lib/sys_socket.in.h	Tue Apr 24 20:04:05 2018 +0200
@@ -215,6 +215,15 @@
 
 #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 <winsock2.h>.  */
 
 #if @HAVE_WINSOCK2_H@
--- a/modules/select-tests	Tue Apr 24 08:09:57 2018 -0700
+++ b/modules/select-tests	Tue Apr 24 20:04:05 2018 +0200
@@ -10,6 +10,7 @@
 
 Depends-on:
 stdbool
+sys_socket
 netinet_in
 arpa_inet
 unistd
--- a/tests/test-poll.c	Tue Apr 24 08:09:57 2018 -0700
+++ b/tests/test-poll.c	Tue Apr 24 20:04:05 2018 +0200
@@ -52,10 +52,6 @@
 #include <sys/wait.h>
 #endif
 
-#ifndef SO_REUSEPORT
-#define SO_REUSEPORT    SO_REUSEADDR
-#endif
-
 #define TEST_PORT       12345
 
 
--- a/tests/test-select.h	Tue Apr 24 08:09:57 2018 -0700
+++ b/tests/test-select.h	Tue Apr 24 20:04:05 2018 +0200
@@ -18,6 +18,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <unistd.h>
@@ -37,10 +38,6 @@
 # include <sys/wait.h>
 #endif
 
-#ifndef SO_REUSEPORT
-# define SO_REUSEPORT    SO_REUSEADDR
-#endif
-
 #define TEST_PORT       12345