(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 = ? "
*/
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
{
struct ClientState *cs;
+ num_clients++;
cs = GNUNET_new (struct ClientState);
cs->client = c;
cs->mq = mq;
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;
+ }
+ }
}
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);