gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37987 - in libmicrohttpd/src: examples microhttpd testcurl


From: gnunet
Subject: [GNUnet-SVN] r37987 - in libmicrohttpd/src: examples microhttpd testcurl
Date: Fri, 23 Sep 2016 16:18:06 +0200

Author: grothoff
Date: 2016-09-23 16:18:06 +0200 (Fri, 23 Sep 2016)
New Revision: 37987

Modified:
   libmicrohttpd/src/examples/fileserver_example_external_select.c
   libmicrohttpd/src/examples/post_example.c
   libmicrohttpd/src/examples/timeout.c
   libmicrohttpd/src/microhttpd/test_upgrade.c
   libmicrohttpd/src/microhttpd/test_upgrade_common.c
   libmicrohttpd/src/testcurl/test_callback.c
   libmicrohttpd/src/testcurl/test_postform.c
   libmicrohttpd/src/testcurl/test_put_chunked.c
   libmicrohttpd/src/testcurl/test_quiesce.c
Log:
add return value checks for a few more system calls in testcases and examples

Modified: libmicrohttpd/src/examples/fileserver_example_external_select.c
===================================================================
--- libmicrohttpd/src/examples/fileserver_example_external_select.c     
2016-09-23 14:06:50 UTC (rev 37986)
+++ libmicrohttpd/src/examples/fileserver_example_external_select.c     
2016-09-23 14:18:06 UTC (rev 37987)
@@ -159,7 +159,11 @@
               tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000LL)) * 1000LL;
             }
         }
-      select (max + 1, &rs, &ws, &es, &tv);
+      if (-1 == select (max + 1, &rs, &ws, &es, &tv))
+        {
+          if (EINTR != errno)
+            abort ();
+        }
       MHD_run (d);
     }
   MHD_stop_daemon (d);

Modified: libmicrohttpd/src/examples/post_example.c
===================================================================
--- libmicrohttpd/src/examples/post_example.c   2016-09-23 14:06:50 UTC (rev 
37986)
+++ libmicrohttpd/src/examples/post_example.c   2016-09-23 14:18:06 UTC (rev 
37987)
@@ -741,7 +741,11 @@
        }
       else
        tvp = NULL;
-      select (max + 1, &rs, &ws, &es, tvp);
+      if (-1 == select (max + 1, &rs, &ws, &es, tvp))
+        {
+          if (EINTR != errno)
+            abort ();
+        }
       MHD_run (d);
     }
   MHD_stop_daemon (d);

Modified: libmicrohttpd/src/examples/timeout.c
===================================================================
--- libmicrohttpd/src/examples/timeout.c        2016-09-23 14:06:50 UTC (rev 
37986)
+++ libmicrohttpd/src/examples/timeout.c        2016-09-23 14:18:06 UTC (rev 
37987)
@@ -21,9 +21,9 @@
   response = MHD_create_response_from_buffer (strlen(page),
                                               (void *) page,
                                               MHD_RESPMEM_PERSISTENT);
-  MHD_add_response_header(response,
-                          MHD_HTTP_HEADER_CONTENT_TYPE,
-                          "text/html");
+  MHD_add_response_header (response,
+                           MHD_HTTP_HEADER_CONTENT_TYPE,
+                           "text/html");
   ret = MHD_queue_response (connection,
                             MHD_HTTP_OK,
                             response);
@@ -32,15 +32,18 @@
 }
 
 
-int main()
+int
+main (int argc,
+      char **argv)
 {
   struct MHD_Daemon *daemon;
 
-  daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION,
-                            PORT, NULL, NULL,
-                            &answer_to_connection, NULL,
-                            MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 3,
-                            MHD_OPTION_END);
+  daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION,
+                             PORT,
+                             NULL, NULL,
+                             &answer_to_connection, NULL,
+                             MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 3,
+                             MHD_OPTION_END);
   if (NULL == daemon)
     return 1;
   getchar();

Modified: libmicrohttpd/src/microhttpd/test_upgrade.c
===================================================================
--- libmicrohttpd/src/microhttpd/test_upgrade.c 2016-09-23 14:06:50 UTC (rev 
37986)
+++ libmicrohttpd/src/microhttpd/test_upgrade.c 2016-09-23 14:18:06 UTC (rev 
37987)
@@ -77,10 +77,11 @@
                     (struct sockaddr *) &sa,
                     sizeof (sa)))
     abort ();
-  pthread_create (&pt_client,
-                  NULL,
-                  &run_usock_client,
-                  &sock);
+  if (0 !- pthread_create (&pt_client,
+                           NULL,
+                           &run_usock_client,
+                           &sock))
+    abort ();
   if (0 == (flags & (MHD_USE_SELECT_INTERNALLY |
                      MHD_USE_THREAD_PER_CONNECTION)) )
     run_mhd_loop (d, flags);

Modified: libmicrohttpd/src/microhttpd/test_upgrade_common.c
===================================================================
--- libmicrohttpd/src/microhttpd/test_upgrade_common.c  2016-09-23 14:06:50 UTC 
(rev 37986)
+++ libmicrohttpd/src/microhttpd/test_upgrade_common.c  2016-09-23 14:18:06 UTC 
(rev 37987)
@@ -301,10 +301,11 @@
   usock = sock;
   if (0 != extra_in_size)
     abort ();
-  pthread_create (&pt,
-                  NULL,
-                  &run_usock,
-                  urh);
+  if (0 != pthread_create (&pt,
+                           NULL,
+                           &run_usock,
+                           urh))
+    abort ();
 }
 
 

Modified: libmicrohttpd/src/testcurl/test_callback.c
===================================================================
--- libmicrohttpd/src/testcurl/test_callback.c  2016-09-23 14:06:50 UTC (rev 
37986)
+++ libmicrohttpd/src/testcurl/test_callback.c  2016-09-23 14:18:06 UTC (rev 
37987)
@@ -174,7 +174,11 @@
        }
       tv.tv_sec = 0;
       tv.tv_usec = 1000;
-      select(maxposixs + 1, &rs, &ws, &es, &tv);
+      if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
+        {
+          if (EINTR != errno)
+            abort ();
+        }
       if (NULL != multi)
        {
          curl_multi_perform (multi, &running);

Modified: libmicrohttpd/src/testcurl/test_postform.c
===================================================================
--- libmicrohttpd/src/testcurl/test_postform.c  2016-09-23 14:06:50 UTC (rev 
37986)
+++ libmicrohttpd/src/testcurl/test_postform.c  2016-09-23 14:18:06 UTC (rev 
37987)
@@ -184,8 +184,8 @@
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
-                        1080, NULL, NULL, &ahc_echo, NULL, 
-                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,       
                
+                        1080, NULL, NULL, &ahc_echo, NULL,
+                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
                        MHD_OPTION_END);
   if (d == NULL)
     return 1;
@@ -240,8 +240,8 @@
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
-                        1081, NULL, NULL, &ahc_echo, NULL, 
-                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,       
                
+                        1081, NULL, NULL, &ahc_echo, NULL,
+                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
                        MHD_OPTION_END);
   if (d == NULL)
     return 16;
@@ -298,7 +298,7 @@
   d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
                         1081, NULL, NULL, &ahc_echo, NULL,
                         MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT,
-                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,       
                
+                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
                        MHD_OPTION_END);
   if (d == NULL)
     return 16;
@@ -368,8 +368,8 @@
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_DEBUG,
-                        1082, NULL, NULL, &ahc_echo, NULL, 
-                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,       
                
+                        1082, NULL, NULL, &ahc_echo, NULL,
+                       MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
                        MHD_OPTION_END);
   if (d == NULL)
     return 256;
@@ -439,7 +439,11 @@
         }
       tv.tv_sec = 0;
       tv.tv_usec = 1000;
-      select (maxposixs + 1, &rs, &ws, &es, &tv);
+      if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
+        {
+          if (EINTR != errno)
+            abort ();
+        }
       curl_multi_perform (multi, &running);
       if (running == 0)
         {
@@ -452,7 +456,8 @@
                 printf ("%s failed at %s:%d: `%s'\n",
                         "curl_multi_perform",
                         __FILE__,
-                        __LINE__, curl_easy_strerror (msg->data.result));
+                        __LINE__,
+                        curl_easy_strerror (msg->data.result));
               curl_multi_remove_handle (multi, c);
               curl_multi_cleanup (multi);
               curl_easy_cleanup (c);

Modified: libmicrohttpd/src/testcurl/test_put_chunked.c
===================================================================
--- libmicrohttpd/src/testcurl/test_put_chunked.c       2016-09-23 14:06:50 UTC 
(rev 37986)
+++ libmicrohttpd/src/testcurl/test_put_chunked.c       2016-09-23 14:18:06 UTC 
(rev 37987)
@@ -397,7 +397,11 @@
         }
       tv.tv_sec = 0;
       tv.tv_usec = 1000;
-      select (maxposixs + 1, &rs, &ws, &es, &tv);
+      if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
+        {
+          if (EINTR != errno)
+            abort ();
+        }
       curl_multi_perform (multi, &running);
       if (running == 0)
         {
@@ -410,7 +414,8 @@
                 printf ("%s failed at %s:%d: `%s'\n",
                         "curl_multi_perform",
                         __FILE__,
-                        __LINE__, curl_easy_strerror (msg->data.result));
+                        __LINE__,
+                        curl_easy_strerror (msg->data.result));
               curl_multi_remove_handle (multi, c);
               curl_multi_cleanup (multi);
               curl_easy_cleanup (c);

Modified: libmicrohttpd/src/testcurl/test_quiesce.c
===================================================================
--- libmicrohttpd/src/testcurl/test_quiesce.c   2016-09-23 14:06:50 UTC (rev 
37986)
+++ libmicrohttpd/src/testcurl/test_quiesce.c   2016-09-23 14:18:06 UTC (rev 
37987)
@@ -155,7 +155,11 @@
         }
       tv.tv_sec = 0;
       tv.tv_usec = 1000;
-      MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv);
+      if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv))
+        {
+          if (EINTR != errno)
+            abort ();
+        }
       MHD_run (d);
     }
   fd = MHD_quiesce_daemon (d);
@@ -350,7 +354,10 @@
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_DEBUG,
-                        11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
+                        11080,
+                        NULL, NULL,
+                        &ahc_echo, "GET",
+                        MHD_OPTION_END);
   if (d == NULL)
     return 256;
   c = setupCURL(&cbc);
@@ -371,91 +378,100 @@
       return 1024;
     }
 
-  for (i = 0; i < 2; i++) {
-    start = time (NULL);
-    while ((time (NULL) - start < 5) && (multi != NULL))
-      {
-        maxsock = MHD_INVALID_SOCKET;
-        maxposixs = -1;
-        FD_ZERO (&rs);
-        FD_ZERO (&ws);
-        FD_ZERO (&es);
-        curl_multi_perform (multi, &running);
-        mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
-        if (mret != CURLM_OK)
-          {
-            curl_multi_remove_handle (multi, c);
-            curl_multi_cleanup (multi);
-            curl_easy_cleanup (c);
-            MHD_stop_daemon (d);
-            return 2048;
-          }
-        if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
-          {
-            curl_multi_remove_handle (multi, c);
-            curl_multi_cleanup (multi);
-            curl_easy_cleanup (c);
-            MHD_stop_daemon (d);
-            return 4096;
-          }
-        tv.tv_sec = 0;
-        tv.tv_usec = 1000;
-        select (maxposixs + 1, &rs, &ws, &es, &tv);
-        curl_multi_perform (multi, &running);
-        if (running == 0)
-          {
-            msg = curl_multi_info_read (multi, &running);
-            if (msg == NULL)
-              break;
-            if (msg->msg == CURLMSG_DONE)
-              {
-                if (i == 0 && msg->data.result != CURLE_OK)
-                  printf ("%s failed at %s:%d: `%s'\n",
-                          "curl_multi_perform",
-                          __FILE__,
-                          __LINE__, curl_easy_strerror (msg->data.result));
-                else if (i == 1 && msg->data.result == CURLE_OK)
-                  printf ("%s should have failed at %s:%d\n",
-                          "curl_multi_perform",
-                          __FILE__,
-                          __LINE__);
-                curl_multi_remove_handle (multi, c);
-                curl_multi_cleanup (multi);
-                curl_easy_cleanup (c);
-                c = NULL;
-                multi = NULL;
-              }
-          }
-        MHD_run (d);
-      }
+  for (i = 0; i < 2; i++)
+    {
+      start = time (NULL);
+      while ( (time (NULL) - start < 5) &&
+              (NULL != multi) )
+        {
+          maxsock = MHD_INVALID_SOCKET;
+          maxposixs = -1;
+          FD_ZERO (&rs);
+          FD_ZERO (&ws);
+          FD_ZERO (&es);
+          curl_multi_perform (multi, &running);
+          mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
+          if (mret != CURLM_OK)
+            {
+              curl_multi_remove_handle (multi, c);
+              curl_multi_cleanup (multi);
+              curl_easy_cleanup (c);
+              MHD_stop_daemon (d);
+              return 2048;
+            }
+          if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
+            {
+              curl_multi_remove_handle (multi, c);
+              curl_multi_cleanup (multi);
+              curl_easy_cleanup (c);
+              MHD_stop_daemon (d);
+              return 4096;
+            }
+          tv.tv_sec = 0;
+          tv.tv_usec = 1000;
+          if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
+            {
+              if (EINTR != errno)
+                abort ();
+            }
+          curl_multi_perform (multi, &running);
+          if (0 == running)
+            {
+              msg = curl_multi_info_read (multi, &running);
+              if (NULL == msg)
+                break;
+              if (msg->msg == CURLMSG_DONE)
+                {
+                  if (i == 0 && msg->data.result != CURLE_OK)
+                    printf ("%s failed at %s:%d: `%s'\n",
+                            "curl_multi_perform",
+                            __FILE__,
+                            __LINE__,
+                            curl_easy_strerror (msg->data.result));
+                  else if ( (i == 1) &&
+                            (msg->data.result == CURLE_OK) )
+                    printf ("%s should have failed at %s:%d\n",
+                            "curl_multi_perform",
+                            __FILE__,
+                            __LINE__);
+                  curl_multi_remove_handle (multi, c);
+                  curl_multi_cleanup (multi);
+                  curl_easy_cleanup (c);
+                  c = NULL;
+                  multi = NULL;
+                }
+            }
+          MHD_run (d);
+        }
 
-      if (i == 0) {
-        /* quiesce the daemon on the 1st iteration, so the 2nd should fail */
-        fd = MHD_quiesce_daemon(d);
-        if (MHD_INVALID_SOCKET == fd)
-          {
-            fprintf (stderr,
-                     "MHD_quiesce_daemon failed.\n");
-            curl_multi_remove_handle (multi, c);
-            curl_multi_cleanup (multi);
-            curl_easy_cleanup (c);
-            MHD_stop_daemon (d);
-            return 2;
-          }
-        c = setupCURL (&cbc);
-        multi = curl_multi_init ();
-        mret = curl_multi_add_handle (multi, c);
-        if (mret != CURLM_OK)
+      if (0 == i)
         {
-          curl_multi_remove_handle (multi, c);
-          curl_multi_cleanup (multi);
-          curl_easy_cleanup (c);
-          MHD_stop_daemon (d);
-          return 32768;
+          /* quiesce the daemon on the 1st iteration, so the 2nd should fail */
+          fd = MHD_quiesce_daemon(d);
+          if (MHD_INVALID_SOCKET == fd)
+            {
+              fprintf (stderr,
+                       "MHD_quiesce_daemon failed.\n");
+              curl_multi_remove_handle (multi, c);
+              curl_multi_cleanup (multi);
+              curl_easy_cleanup (c);
+              MHD_stop_daemon (d);
+              return 2;
+            }
+          c = setupCURL (&cbc);
+          multi = curl_multi_init ();
+          mret = curl_multi_add_handle (multi, c);
+          if (mret != CURLM_OK)
+            {
+              curl_multi_remove_handle (multi, c);
+              curl_multi_cleanup (multi);
+              curl_easy_cleanup (c);
+              MHD_stop_daemon (d);
+              return 32768;
+            }
         }
-      }
     }
-  if (multi != NULL)
+  if (NULL != multi)
     {
       curl_multi_remove_handle (multi, c);
       curl_easy_cleanup (c);




reply via email to

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