more client disconnect code
authorChristian Grothoff <christian@grothoff.org>
Thu, 13 Oct 2011 21:01:22 +0000 (21:01 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 13 Oct 2011 21:01:22 +0000 (21:01 +0000)
src/ats/gnunet-service-ats.c
src/ats/gnunet-service-ats_performance.c
src/ats/gnunet-service-ats_scheduling.c

index 3e1a5e5adb314a659167c10ff43cc82005f0fffb..19a5d438049d911b595c60d932078afcab5f8f62 100644 (file)
@@ -60,7 +60,6 @@ handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
 }
 
 
-
 /**
  * A client disconnected from us.  Tear down the local client
  * record.
index fa60e4973ea31c7236333bf3b45ba5d435236977..edad2251210dfabc79f004e613a01de058b413da 100644 (file)
@@ -48,6 +48,18 @@ static struct PerformanceClient *pc_head;
  * Tail of linked list of all clients to this service.
  */
 static struct PerformanceClient *pc_tail;
+
+static struct PerformanceClient * 
+find_client (struct GNUNET_SERVER_Client *client)
+{
+  struct PerformanceClient * pc;
+
+  for (pc = pc_head; pc != NULL; pc = pc->next)
+    if (pc->client == client)
+      return pc;
+  return NULL;
+}
 
 
 void
@@ -55,6 +67,7 @@ GAS_add_performance_client (struct GNUNET_SERVER_Client *client)
 {
   struct PerformanceClient * pc;
 
+  GNUNET_break (NULL == find_client (client));
   pc = GNUNET_malloc (sizeof (struct PerformanceClient));
   pc->client = client;
   GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc);
@@ -64,6 +77,14 @@ GAS_add_performance_client (struct GNUNET_SERVER_Client *client)
 void
 GAS_remove_performance_client (struct GNUNET_SERVER_Client *client)
 {
+  struct PerformanceClient * pc;
+
+  pc = find_client (client);
+  if (NULL == pc)
+    return;
+  GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
+  GNUNET_SERVER_client_drop (client);
+  GNUNET_free (pc);
 }
 
 
index 9400e12ff5c3228b899047565a24eb84e8d88fb1..bf2c6187ab5dbc3fd2640a03dee6e2dcd530047d 100644 (file)
@@ -42,29 +42,50 @@ struct SchedulingClient
 /**
  * Head of linked list of all clients to this service.
  */
-static struct SchedulingClient *ac_head;
+static struct SchedulingClient *sc_head;
 
 /**
  * Tail of linked list of all clients to this service.
  */
-static struct SchedulingClient *ac_tail;
+static struct SchedulingClient *sc_tail;
+
+
+static struct SchedulingClient * 
+find_client (struct GNUNET_SERVER_Client *client)
+{
+  struct SchedulingClient * sc;
+
+  for (sc = sc_head; sc != NULL; sc = sc->next)
+    if (sc->client == client)
+      return sc;
+  return NULL;
+}
 
 
 void
 GAS_add_scheduling_client (struct GNUNET_SERVER_Client *client)
 {
-  struct SchedulingClient *ac;
+  struct SchedulingClient *sc;
 
-  ac = GNUNET_malloc (sizeof (struct SchedulingClient));
-  ac->client = client;
+  GNUNET_break (NULL == find_client (client));
+  sc = GNUNET_malloc (sizeof (struct SchedulingClient));
+  sc->client = client;
   GNUNET_SERVER_client_keep (client);
-  GNUNET_CONTAINER_DLL_insert(ac_head, ac_tail, ac);
+  GNUNET_CONTAINER_DLL_insert(sc_head, sc_tail, sc);
 }
 
 
 void
 GAS_remove_scheduling_client (struct GNUNET_SERVER_Client *client)
 {
+  struct SchedulingClient * sc;
+
+  sc = find_client (client);
+  if (NULL == sc)
+    return;
+  GNUNET_CONTAINER_DLL_remove (sc_head, sc_tail, sc);
+  GNUNET_SERVER_client_drop (client);
+  GNUNET_free (sc);
 }