bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] set SO_REUSE* before bind(), not after


From: Ed Maste
Subject: [PATCH] set SO_REUSE* before bind(), not after
Date: Mon, 1 Oct 2012 16:51:23 -0400

While investigating skipped tests on FreeBSD I found that test-poll
and test-select were skipped due to bind() returning EADDRINUSE.  It
turns out that these tests call setsockopt(..., SO_REUSE... after
calling bind(), not before.

diff --git a/tests/test-poll.c b/tests/test-poll.c
index 7ba0280..69a30f0 100644
--- a/tests/test-poll.c
+++ b/tests/test-poll.c
@@ -96,6 +96,9 @@ open_server_socket ()

   s = socket (AF_INET, SOCK_STREAM, 0);

+  x = 1;
+++ b/tests/test-poll.c
@@ -96,6 +96,9 @@ open_server_socket ()

   s = socket (AF_INET, SOCK_STREAM, 0);

+  x = 1;
+  setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
+
   memset (&ia, 0, sizeof (ia));
   ia.sin_family = AF_INET;
   inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
@@ -106,9 +109,6 @@ open_server_socket ()
       exit (77);
     }

-  x = 1;
-  setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
-
   if (listen (s, 1) < 0)
     {
       perror ("listen");
diff --git a/tests/test-select.h b/tests/test-select.h
index 1169e59..af0e38c 100644
--- a/tests/test-select.h
+++ b/tests/test-select.h
@@ -84,6 +84,9 @@ open_server_socket (void)

   s = socket (AF_INET, SOCK_STREAM, 0);

+  x = 1;
+  setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
+
   memset (&ia, 0, sizeof (ia));
   ia.sin_family = AF_INET;
   inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
@@ -94,9 +97,6 @@ open_server_socket (void)
       exit (77);
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]