gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] 02/02: tests: check whether MHD use SO_REUS


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 02/02: tests: check whether MHD use SO_REUSEADDR by default
Date: Sun, 26 Nov 2017 21:01:07 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit d951b950ec1af5e6ba582a8a964dff2d9192ba41
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Sun Nov 26 19:34:55 2017 +0300

    tests: check whether MHD use SO_REUSEADDR by default
---
 src/testcurl/test_get.c | 134 ++++++++++++++++++++++++------------------------
 1 file changed, 68 insertions(+), 66 deletions(-)

diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c
index b16c1554..4f4a0944 100644
--- a/src/testcurl/test_get.c
+++ b/src/testcurl/test_get.c
@@ -55,6 +55,7 @@
 #endif
 
 static int oneone;
+static int global_port;
 
 struct CBC
 {
@@ -117,35 +118,35 @@ testInternalGet (int poll_flag)
   char buf[2048];
   struct CBC cbc;
   CURLcode errornum;
-  int port;
 
-  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
-    port = 0;
-  else
+  if (0 == global_port)
     {
-      port = 1220;
-      if (oneone)
-        port += 20;
+      if (MHD_NO == MHD_is_feature_supported 
(MHD_FEATURE_AUTODETECT_BIND_PORT))
+       {
+         global_port = 1220;
+         if (oneone)
+           global_port += 20;
+       }
     }
 
   cbc.buf = buf;
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG  | 
poll_flag,
-                        port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
+                        global_port, NULL, NULL, &ahc_echo, "GET", 
MHD_OPTION_END);
   if (d == NULL)
     return 1;
-  if (0 == port)
+  if (0 == global_port)
     {
       const union MHD_DaemonInfo *dinfo;
       dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
       if (NULL == dinfo || 0 == dinfo->port)
         { MHD_stop_daemon (d); return 32; }
-      port = (int)dinfo->port;
+      global_port = (int)dinfo->port;
     }
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world";);
-  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
@@ -186,35 +187,35 @@ testMultithreadedGet (int poll_flag)
   char buf[2048];
   struct CBC cbc;
   CURLcode errornum;
-  int port;
 
-  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
-    port = 0;
-  else
+  if (0 == global_port)
     {
-      port = 1221;
-      if (oneone)
-        port += 20;
+      if (MHD_NO == MHD_is_feature_supported 
(MHD_FEATURE_AUTODETECT_BIND_PORT))
+       {
+         global_port = 1221;
+         if (oneone)
+           global_port += 20;
+       }
     }
 
   cbc.buf = buf;
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG  | poll_flag,
-                        port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
+                        global_port, NULL, NULL, &ahc_echo, "GET", 
MHD_OPTION_END);
   if (d == NULL)
     return 16;
-  if (0 == port)
+  if (0 == global_port)
     {
       const union MHD_DaemonInfo *dinfo;
       dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
       if (NULL == dinfo || 0 == dinfo->port)
         { MHD_stop_daemon (d); return 32; }
-      port = (int)dinfo->port;
+      global_port = (int)dinfo->port;
     }
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world";);
-  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
@@ -255,36 +256,36 @@ testMultithreadedPoolGet (int poll_flag)
   char buf[2048];
   struct CBC cbc;
   CURLcode errornum;
-  int port;
 
-  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
-    port = 0;
-  else
+  if (0 == global_port)
     {
-      port = 1222;
-      if (oneone)
-        port += 20;
+      if (MHD_NO == MHD_is_feature_supported 
(MHD_FEATURE_AUTODETECT_BIND_PORT))
+       {
+         global_port = 1222;
+         if (oneone)
+           global_port += 20;
+       }
     }
 
   cbc.buf = buf;
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | 
poll_flag,
-                        port, NULL, NULL, &ahc_echo, "GET",
+                        global_port, NULL, NULL, &ahc_echo, "GET",
                         MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, 
MHD_OPTION_END);
   if (d == NULL)
     return 16;
-  if (0 == port)
+  if (0 == global_port)
     {
       const union MHD_DaemonInfo *dinfo;
       dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
       if (NULL == dinfo || 0 == dinfo->port)
         { MHD_stop_daemon (d); return 32; }
-      port = (int)dinfo->port;
+      global_port = (int)dinfo->port;
     }
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world";);
-  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
@@ -339,15 +340,15 @@ testExternalGet ()
   struct CURLMsg *msg;
   time_t start;
   struct timeval tv;
-  int port;
 
-  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
-    port = 0;
-  else
+  if (0 == global_port)
     {
-      port = 1223;
-      if (oneone)
-        port += 20;
+      if (MHD_NO == MHD_is_feature_supported 
(MHD_FEATURE_AUTODETECT_BIND_PORT))
+       {
+         global_port = 1223;
+         if (oneone)
+           global_port += 20;
+       }
     }
 
   multi = NULL;
@@ -355,20 +356,20 @@ testExternalGet ()
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_ERROR_LOG,
-                        port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
+                        global_port, NULL, NULL, &ahc_echo, "GET", 
MHD_OPTION_END);
   if (d == NULL)
     return 256;
-  if (0 == port)
+  if (0 == global_port)
     {
       const union MHD_DaemonInfo *dinfo;
       dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
       if (NULL == dinfo || 0 == dinfo->port)
         { MHD_stop_daemon (d); return 32; }
-      port = (int)dinfo->port;
+      global_port = (int)dinfo->port;
     }
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world";);
-  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
@@ -565,28 +566,28 @@ testStopRace (int poll_flag)
     struct sockaddr_in sin;
     MHD_socket fd;
     struct MHD_Daemon *d;
-    int port;
 
-    if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
-      port = 0;
-    else
+    if (0 == global_port)
       {
-        port = 1224;
-        if (oneone)
-          port += 20;
+       if (MHD_NO == MHD_is_feature_supported 
(MHD_FEATURE_AUTODETECT_BIND_PORT))
+         {
+           global_port = 1224;
+           if (oneone)
+             global_port += 20;
+         }
       }
 
     d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | poll_flag,
-                         port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
+                         global_port, NULL, NULL, &ahc_echo, "GET", 
MHD_OPTION_END);
     if (d == NULL)
        return 16;
-    if (0 == port)
+    if (0 == global_port)
       {
         const union MHD_DaemonInfo *dinfo;
         dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
         if (NULL == dinfo || 0 == dinfo->port)
           { MHD_stop_daemon (d); return 32; }
-        port = (int)dinfo->port;
+        global_port = (int)dinfo->port;
       }
 
     fd = socket (PF_INET, SOCK_STREAM, 0);
@@ -598,7 +599,7 @@ testStopRace (int poll_flag)
 
     memset(&sin, 0, sizeof(sin));
     sin.sin_family = AF_INET;
-    sin.sin_port = htons(port);
+    sin.sin_port = htons(global_port);
     sin.sin_addr.s_addr = htonl(0x7f000001);
 
     if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0)
@@ -680,35 +681,35 @@ testEmptyGet (int poll_flag)
   struct CBC cbc;
   CURLcode errornum;
   int excess_found = 0;
-  int port;
 
-  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
-    port = 0;
-  else
+  if (0 == global_port)
     {
-      port = 1225;
-      if (oneone)
-        port += 20;
+      if (MHD_NO == MHD_is_feature_supported 
(MHD_FEATURE_AUTODETECT_BIND_PORT))
+       {
+         global_port = 1225;
+         if (oneone)
+           global_port += 20;
+       }
     }
 
   cbc.buf = buf;
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG  | 
poll_flag,
-                        port, NULL, NULL, &ahc_empty, NULL, MHD_OPTION_END);
+                        global_port, NULL, NULL, &ahc_empty, NULL, 
MHD_OPTION_END);
   if (d == NULL)
     return 4194304;
-  if (0 == port)
+  if (0 == global_port)
     {
       const union MHD_DaemonInfo *dinfo;
       dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
       if (NULL == dinfo || 0 == dinfo->port)
         { MHD_stop_daemon (d); return 32; }
-      port = (int)dinfo->port;
+      global_port = (int)dinfo->port;
     }
   c = curl_easy_init ();
   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world";);
-  curl_easy_setopt (c, CURLOPT_PORT, (long)port);
+  curl_easy_setopt (c, CURLOPT_PORT, (long)global_port);
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound);
@@ -754,6 +755,7 @@ main (int argc, char *const *argv)
     (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
     return 2;
+  global_port = 0;
   errorCount += testInternalGet (0);
   errorCount += testMultithreadedGet (0);
   errorCount += testMultithreadedPoolGet (0);

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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