gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r32589 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r32589 - gnunet/src/testbed
Date: Fri, 7 Mar 2014 16:57:34 +0100

Author: harsha
Date: 2014-03-07 16:57:34 +0100 (Fri, 07 Mar 2014)
New Revision: 32589

Modified:
   gnunet/src/testbed/gnunet-service-testbed-logger.c
Log:
- Delay shutdown until all connections are closed.


Modified: gnunet/src/testbed/gnunet-service-testbed-logger.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed-logger.c  2014-03-07 15:52:26 UTC 
(rev 32588)
+++ gnunet/src/testbed/gnunet-service-testbed-logger.c  2014-03-07 15:57:34 UTC 
(rev 32589)
@@ -86,6 +86,16 @@
 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
 
 /**
+ * The number of connections we have
+ */
+static unsigned int nconn;
+
+/**
+ * Are we shutting down?
+ */
+static int in_shutdown;
+
+/**
  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
  *
  * @param cls NULL
@@ -117,6 +127,15 @@
   struct MessageQueue *mq_entry;
 
   shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
+  in_shutdown = GNUNET_YES;
+  if (0 != nconn)
+  {
+    /* Delay shutdown if there are active connections */
+    shutdown_task_id = GNUNET_SCHEDULER_add_delayed
+        (GNUNET_TIME_UNIT_FOREVER_REL,
+         &shutdown_task, NULL);
+    return;
+  }
   while (NULL != (mq_entry = mq_head))
   {
     GNUNET_free (mq_entry->msg);
@@ -129,6 +148,51 @@
 
 
 /**
+ * Functions with this signature are called whenever a client
+ * is disconnected on the network level.
+ *
+ * @param cls closure
+ * @param client identification of the client; NULL
+ *        for the last call when the server is destroyed
+ */
+static void 
+client_disconnected (void *cls, struct GNUNET_SERVER_Client *client)
+{
+  if (NULL == client)
+  {
+    GNUNET_break (0 == nconn);
+    return;
+  }
+  nconn--;
+  if (GNUNET_YES != in_shutdown)
+    return;
+  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != shutdown_task_id);
+  GNUNET_SCHEDULER_cancel (shutdown_task_id);
+  shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+}
+
+
+/**
+ * Functions with this signature are called whenever a client
+ * is connected on the network level.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ */
+static void
+client_connected (void *cls, struct GNUNET_SERVER_Client *client)
+{
+  if (NULL == client)
+  {
+    GNUNET_break (0 == nconn);
+    return;
+  }
+  GNUNET_SERVER_client_persist_ (client);
+  nconn++;
+}
+
+
+/**
  * Testbed setup
  *
  * @param cls closure
@@ -180,6 +244,8 @@
   }
   GNUNET_free (fn);
   GNUNET_SERVER_add_handlers (server, message_handlers);
+  GNUNET_SERVER_connect_notify (server, &client_connected, NULL);
+  GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL);
   shutdown_task_id =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                     &shutdown_task, NULL);




reply via email to

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