Use statement exprs instead of local function
[oweals/gnunet.git] / src / gns / gnunet-gns.c
index f4f1946a7d7d863cfc4042de64864eba77a2c598..62cec54cb1065534c0b332337ebd420b52870cc6 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012-2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012-2013 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
@@ -100,16 +100,19 @@ static struct GNUNET_IDENTITY_Handle *identity;
  */
 static struct GNUNET_IDENTITY_Operation *id_op;
 
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
 
 /**
  * Task run on shutdown.  Cleans up everything.
  *
  * @param cls unused
- * @param tc scheduler context
  */
 static void
-do_shutdown (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
 {
   if (NULL != el)
   {
@@ -136,6 +139,24 @@ do_shutdown (void *cls,
     GNUNET_GNS_disconnect (gns);
     gns = NULL;
   }
+  if (NULL != tt)
+  {
+    GNUNET_SCHEDULER_cancel (tt);
+    tt = NULL;
+  }
+}
+
+
+/**
+ * Task run on timeout. Triggers shutdown.
+ *
+ * @param cls unused
+ */
+static void
+do_timeout (void *cls)
+{
+  tt = NULL;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -378,7 +399,9 @@ identity_master_cb (void *cls,
  * @param c configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
@@ -392,8 +415,9 @@ run (void *cls, char *const *args, const char *cfgfile,
             _("Failed to connect to GNS\n"));
     return;
   }
-  GNUNET_SCHEDULER_add_delayed (timeout,
-                               &do_shutdown, NULL);
+  tt = GNUNET_SCHEDULER_add_delayed (timeout,
+                                    &do_timeout, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
   if (NULL != public_key)
   {
     if (GNUNET_OK !=