aboutsummaryrefslogtreecommitdiff
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;
155static struct Listener *listener_tail; 155static struct Listener *listener_tail;
156 156
157/** 157/**
158 * Number of active clients.
159 */
160static unsigned int num_clients;
161
162/**
163 * Are we in shutdown? if #GNUNET_YES and the number of clients
164 * drops to zero, disconnect from CADET.
165 */
166static int in_shutdown;
167
168/**
158 * Counter for allocating unique IDs for clients, used to identify 169 * Counter for allocating unique IDs for clients, used to identify
159 * incoming operation requests from remote peers, that the client can 170 * incoming operation requests from remote peers, that the client can
160 * choose to accept or refuse. 0 must not be used (reserved for 171 * choose to accept or refuse. 0 must not be used (reserved for
@@ -485,6 +496,7 @@ client_connect_cb (void *cls,
485{ 496{
486 struct ClientState *cs; 497 struct ClientState *cs;
487 498
499 num_clients++;
488 cs = GNUNET_new (struct ClientState); 500 cs = GNUNET_new (struct ClientState);
489 cs->client = c; 501 cs->client = c;
490 cs->mq = mq; 502 cs->mq = mq;
@@ -623,6 +635,16 @@ client_disconnect_cb (void *cls,
623 GNUNET_free (listener); 635 GNUNET_free (listener);
624 } 636 }
625 GNUNET_free (cs); 637 GNUNET_free (cs);
638 num_clients--;
639 if ( (GNUNET_YES == in_shutdown) &&
640 (0 == num_clients) )
641 {
642 if (NULL != cadet)
643 {
644 GNUNET_CADET_disconnect (cadet);
645 cadet = NULL;
646 }
647 }
626} 648}
627 649
628 650
@@ -1917,10 +1939,14 @@ static void
1917shutdown_task (void *cls) 1939shutdown_task (void *cls)
1918{ 1940{
1919 /* Delay actual shutdown to allow service to disconnect clients */ 1941 /* Delay actual shutdown to allow service to disconnect clients */
1920 if (NULL != cadet) 1942 in_shutdown = GNUNET_YES;
1943 if (0 == num_clients)
1921 { 1944 {
1922 GNUNET_CADET_disconnect (cadet); 1945 if (NULL != cadet)
1923 cadet = NULL; 1946 {
1947 GNUNET_CADET_disconnect (cadet);
1948 cadet = NULL;
1949 }
1924 } 1950 }
1925 GNUNET_STATISTICS_destroy (_GSS_statistics, 1951 GNUNET_STATISTICS_destroy (_GSS_statistics,
1926 GNUNET_YES); 1952 GNUNET_YES);