aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/gnunet-service-set.c')
-rw-r--r--src/set/gnunet-service-set.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index f98d43a7d..42d06b275 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;
@@ -616,13 +628,29 @@ client_disconnect_cb (void *cls,
616 GNUNET_CADET_close_port (listener->open_port); 628 GNUNET_CADET_close_port (listener->open_port);
617 listener->open_port = NULL; 629 listener->open_port = NULL;
618 while (NULL != (op = listener->op_head)) 630 while (NULL != (op = listener->op_head))
631 {
632 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
633 "Destroying incoming operation `%u' from peer `%s'\n",
634 (unsigned int) op->client_request_id,
635 GNUNET_i2s (&op->peer));
619 incoming_destroy (op); 636 incoming_destroy (op);
637 }
620 GNUNET_CONTAINER_DLL_remove (listener_head, 638 GNUNET_CONTAINER_DLL_remove (listener_head,
621 listener_tail, 639 listener_tail,
622 listener); 640 listener);
623 GNUNET_free (listener); 641 GNUNET_free (listener);
624 } 642 }
625 GNUNET_free (cs); 643 GNUNET_free (cs);
644 num_clients--;
645 if ( (GNUNET_YES == in_shutdown) &&
646 (0 == num_clients) )
647 {
648 if (NULL != cadet)
649 {
650 GNUNET_CADET_disconnect (cadet);
651 cadet = NULL;
652 }
653 }
626} 654}
627 655
628 656
@@ -1299,6 +1327,7 @@ handle_client_listen (void *cls,
1299 } 1327 }
1300 listener = GNUNET_new (struct Listener); 1328 listener = GNUNET_new (struct Listener);
1301 listener->cs = cs; 1329 listener->cs = cs;
1330 cs->listener = listener;
1302 listener->app_id = msg->app_id; 1331 listener->app_id = msg->app_id;
1303 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); 1332 listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation);
1304 GNUNET_CONTAINER_DLL_insert (listener_head, 1333 GNUNET_CONTAINER_DLL_insert (listener_head,
@@ -1917,10 +1946,14 @@ static void
1917shutdown_task (void *cls) 1946shutdown_task (void *cls)
1918{ 1947{
1919 /* Delay actual shutdown to allow service to disconnect clients */ 1948 /* Delay actual shutdown to allow service to disconnect clients */
1920 if (NULL != cadet) 1949 in_shutdown = GNUNET_YES;
1950 if (0 == num_clients)
1921 { 1951 {
1922 GNUNET_CADET_disconnect (cadet); 1952 if (NULL != cadet)
1923 cadet = NULL; 1953 {
1954 GNUNET_CADET_disconnect (cadet);
1955 cadet = NULL;
1956 }
1924 } 1957 }
1925 GNUNET_STATISTICS_destroy (_GSS_statistics, 1958 GNUNET_STATISTICS_destroy (_GSS_statistics,
1926 GNUNET_YES); 1959 GNUNET_YES);