summaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index f98d43a7d..056f70f32 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -155,6 +155,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
* choose to accept or refuse. 0 must not be used (reserved for
@@ -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);