gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37072 - libmicrohttpd/src/testcurl


From: gnunet
Subject: [GNUnet-SVN] r37072 - libmicrohttpd/src/testcurl
Date: Sun, 24 Apr 2016 17:16:40 +0200

Author: Karlson2k
Date: 2016-04-24 17:16:39 +0200 (Sun, 24 Apr 2016)
New Revision: 37072

Modified:
   libmicrohttpd/src/testcurl/test_concurrent_stop.c
Log:
Properly cleanup resources in test_concurrent_stop

Modified: libmicrohttpd/src/testcurl/test_concurrent_stop.c
===================================================================
--- libmicrohttpd/src/testcurl/test_concurrent_stop.c   2016-04-23 20:20:12 UTC 
(rev 37071)
+++ libmicrohttpd/src/testcurl/test_concurrent_stop.c   2016-04-24 15:16:39 UTC 
(rev 37072)
@@ -100,6 +100,16 @@
   return ret;
 }
 
+static void
+clean_curl(void * param)
+{
+  if (param)
+    {
+      CURL * const c = *((CURL **)param);
+      if (c)
+        curl_easy_cleanup (c);
+    }
+}
 
 static void *
 thread_gets (void *param)
@@ -108,39 +118,46 @@
   CURLcode errornum;
   unsigned int i;
   char * const url = (char*) param;
+  int pth_olst;
+  if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &pth_olst) ||
+      pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &pth_olst) )
+    {
+      fprintf(stderr,
+              "pthread_setcancelstate()/pthread_setcanceltype() failed.\n");
+      _exit(99);
+    }
 
   for (i=0;i<ROUNDS;i++)
     {
+      pthread_testcancel();
+      c = NULL;
+      pthread_cleanup_push(clean_curl, (void*)&c);
       c = curl_easy_init ();
+      pthread_testcancel();
       curl_easy_setopt (c, CURLOPT_URL, url);
       curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
       curl_easy_setopt (c, CURLOPT_WRITEDATA, NULL);
       curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
-      curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
+      curl_easy_setopt (c, CURLOPT_TIMEOUT, 5L);
       if (oneone)
         curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
       else
         curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
-      curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
+      curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L);
       /* NOTE: use of CONNECTTIMEOUT without also
          setting NOSIGNAL results in really weird
          crashes on my system! */
       curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
-      if (CURLE_OK != (errornum = curl_easy_perform (c)))
-        {
-          curl_easy_cleanup (c);
-          return NULL;
-        }
-      curl_easy_cleanup (c);
+      pthread_testcancel();
+      errornum = curl_easy_perform (c);
+      pthread_cleanup_pop (1);
+      if (CURLE_OK != errornum)
+        return NULL;
     }
 
   return NULL;
 }
 
-#ifndef SIGKILL
-#define SIGKILL SIGTERM
-#endif /* ! SIGKILL */
-
 static void *
 do_gets (void * param)
 {
@@ -155,16 +172,19 @@
     {
       if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url))
         {
+          fprintf(stderr, "pthread_create failed.\n");
           for (j--; j >= 0; j--)
-            pthread_join(par[j], NULL);
-
-          fprintf(stderr, "pthread_create failed.\n");
+            {
+              pthread_cancel(par[j]);
+              pthread_join(par[j], NULL);
+            }
           _exit(99);
         }
     }
+  sleep (1);
   for (j=0;j<PAR;j++)
     {
-      pthread_kill(par[j], SIGKILL);
+      pthread_cancel(par[j]);
       pthread_join(par[j], NULL);
     }
   return NULL;




reply via email to

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