use c99
[oweals/gnunet.git] / src / set / test_set_api.c
index 54c7fd0a825c03e108286fc091772fe9f1b76cf6..d04877b39744852bd52e18b43c48971f56796dc4 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2012 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -44,6 +44,8 @@ static unsigned int iter_count;
 
 static int ret;
 
+static struct GNUNET_SCHEDULER_Task *tt;
+
 
 static void
 result_cb_set1 (void *cls,
@@ -61,6 +63,8 @@ result_cb_set1 (void *cls,
     fprintf (stderr,
              "set 1: received failure status!\n");
     ret = 1;
+    GNUNET_SCHEDULER_cancel (tt);
+    tt = NULL;
     GNUNET_SCHEDULER_shutdown ();
     break;
   case GNUNET_SET_STATUS_DONE:
@@ -69,7 +73,11 @@ result_cb_set1 (void *cls,
     GNUNET_SET_destroy (set1);
     set1 = NULL;
     if (NULL == set2)
+    {
+      GNUNET_SCHEDULER_cancel (tt);
+      tt = NULL;
       GNUNET_SCHEDULER_shutdown ();
+    }
     break;
   default:
     GNUNET_assert (0);
@@ -100,7 +108,11 @@ result_cb_set2 (void *cls,
     GNUNET_SET_destroy (set2);
     set2 = NULL;
     if (NULL == set1)
+    {
+      GNUNET_SCHEDULER_cancel (tt);
+      tt = NULL;
       GNUNET_SCHEDULER_shutdown ();
+    }
     break;
   default:
     GNUNET_assert (0);
@@ -246,14 +258,11 @@ test_iter ()
  * Signature of the main function of a task.
  *
  * @param cls closure
- * @param tc context information (why was this task triggered now)
  */
 static void
-timeout_fail (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_fail (void *cls)
 {
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
+  tt = NULL;
   GNUNET_SCHEDULER_shutdown ();
   ret = 1;
 }
@@ -275,8 +284,8 @@ run (void *cls,
 
   struct GNUNET_SET_OperationHandle *my_oh;
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
-                                &timeout_fail, NULL);
+  tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+                                    &timeout_fail, NULL);
 
   config = cfg;
   GNUNET_CRYPTO_get_peer_identity (cfg, &local_id);
@@ -316,4 +325,3 @@ main (int argc, char **argv)
   }
   return ret;
 }
-