disconnect CADET only after client count hits zero
authorChristian Grothoff <christian@grothoff.org>
Mon, 2 Oct 2017 07:36:09 +0000 (09:36 +0200)
committerChristian Grothoff <christian@grothoff.org>
Mon, 2 Oct 2017 07:36:09 +0000 (09:36 +0200)
src/datastore/plugin_datastore_sqlite.c
src/set/gnunet-service-set.c

index 2d539cb19149ef58934c1488a3569ec729e903b3..cc56f59599058e36ce3976faaacfccf431e2fc60 100644 (file)
@@ -355,40 +355,24 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
                     "SELECT " RESULT_COLUMNS " FROM gn091 "
-#if SQLITE_VERSION_NUMBER >= 3007000
-                    "INDEXED BY idx_repl_rvalue "
-#endif
                     "WHERE repl=?2 AND " " (rvalue>=?1 OR "
                     "  NOT EXISTS (SELECT 1 FROM gn091 "
-#if SQLITE_VERSION_NUMBER >= 3007000
-                    "INDEXED BY idx_repl_rvalue "
-#endif
                     "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
                     "ORDER BY rvalue ASC LIMIT 1",
                     &plugin->selRepl)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
-                    "SELECT MAX(repl) FROM gn091"
-#if SQLITE_VERSION_NUMBER >= 3007000
-                    " INDEXED BY idx_repl_rvalue"
-#endif
-                    "",
+                    "SELECT MAX(repl) FROM gn091",
                     &plugin->maxRepl)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
                     "SELECT " RESULT_COLUMNS " FROM gn091 "
-#if SQLITE_VERSION_NUMBER >= 3007000
-                    "INDEXED BY idx_expire "
-#endif
                     "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
                     "ORDER BY expire ASC LIMIT 1",
                     &plugin->selExpi)) ||
        (SQLITE_OK !=
         sq_prepare (plugin->dbh,
                     "SELECT " RESULT_COLUMNS " FROM gn091 "
-#if SQLITE_VERSION_NUMBER >= 3007000
-                    "INDEXED BY idx_anon_type "
-#endif
                     "WHERE _ROWID_ >= ? AND "
                     "anonLevel = 0 AND "
                     "type = ? "
index f98d43a7de541fed04c42f0d233dffb8b6fc9153..056f70f326f748baf85716d272d1acc91ffb9472 100644 (file)
@@ -154,6 +154,17 @@ static struct Listener *listener_head;
  */
 static struct Listener *listener_tail;
 
+/**
+ * Number of active clients.
+ */
+static unsigned int num_clients;
+
+/**
+ * Are we in shutdown? if #GNUNET_YES and the number of clients
+ * drops to zero, disconnect from CADET.
+ */
+static int in_shutdown;
+
 /**
  * Counter for allocating unique IDs for clients, used to identify
  * incoming operation requests from remote peers, that the client can
@@ -485,6 +496,7 @@ client_connect_cb (void *cls,
 {
   struct ClientState *cs;
 
+  num_clients++;
   cs = GNUNET_new (struct ClientState);
   cs->client = c;
   cs->mq = mq;
@@ -623,6 +635,16 @@ client_disconnect_cb (void *cls,
     GNUNET_free (listener);
   }
   GNUNET_free (cs);
+  num_clients--;
+  if ( (GNUNET_YES == in_shutdown) &&
+       (0 == num_clients) )
+  {
+    if (NULL != cadet)
+    {
+      GNUNET_CADET_disconnect (cadet);
+      cadet = NULL;
+    }
+  }
 }
 
 
@@ -1917,10 +1939,14 @@ static void
 shutdown_task (void *cls)
 {
   /* Delay actual shutdown to allow service to disconnect clients */
-  if (NULL != cadet)
+  in_shutdown = GNUNET_YES;
+  if (0 == num_clients)
   {
-    GNUNET_CADET_disconnect (cadet);
-    cadet = NULL;
+    if (NULL != cadet)
+    {
+      GNUNET_CADET_disconnect (cadet);
+      cadet = NULL;
+    }
   }
   GNUNET_STATISTICS_destroy (_GSS_statistics,
                              GNUNET_YES);