gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10391 - gnunet/src/datastore


From: gnunet
Subject: [GNUnet-SVN] r10391 - gnunet/src/datastore
Date: Mon, 22 Feb 2010 11:05:24 +0100

Author: grothoff
Date: 2010-02-22 11:05:24 +0100 (Mon, 22 Feb 2010)
New Revision: 10391

Modified:
   gnunet/src/datastore/gnunet-service-datastore.c
Log:
better cleanup

Modified: gnunet/src/datastore/gnunet-service-datastore.c
===================================================================
--- gnunet/src/datastore/gnunet-service-datastore.c     2010-02-22 08:53:48 UTC 
(rev 10390)
+++ gnunet/src/datastore/gnunet-service-datastore.c     2010-02-22 10:05:24 UTC 
(rev 10391)
@@ -174,12 +174,31 @@
                                     int status);
 
 
+/**
+ * Context for transmitting replies to clients.
+ */
 struct TransmitCallbackContext 
 {
+  
   /**
+   * We keep these in a doubly-linked list (for cleanup).
+   */
+  struct TransmitCallbackContext *next;
+  
+  /**
+   * We keep these in a doubly-linked list (for cleanup).
+   */
+  struct TransmitCallbackContext *prev;
+  
+  /**
    * The message that we're asked to transmit.
    */
   struct GNUNET_MessageHeader *msg;
+  
+  /**
+   * Handle for the transmission request.
+   */
+  struct GNUNET_CONNECTION_TransmitHandle *th;
 
   /**
    * Client that we are transmitting to.
@@ -204,8 +223,19 @@
   int end;
 };
 
+  
+/**
+ * Head of the doubly-linked list (for cleanup).
+ */
+static struct TransmitCallbackContext *tcc_head;
 
 /**
+ * Tail of the doubly-linked list (for cleanup).
+ */
+static struct TransmitCallbackContext *tcc_tail;
+
+
+/**
  * Task that is used to remove expired entries from
  * the datastore.  This task will schedule itself
  * again automatically to always delete all expired
@@ -410,6 +440,10 @@
   struct TransmitCallbackContext *tcc = cls;
   size_t msize;
   
+  tcc->th = NULL;
+  GNUNET_CONTAINER_DLL_remove (tcc_head,
+                              tcc_tail,
+                              tcc);
   msize = ntohs(tcc->msg->size);
   if (size == 0)
     {
@@ -474,13 +508,12 @@
   tcc->tc = tc;
   tcc->tc_cls = tc_cls;
   tcc->end = end;
-
   if (NULL ==
-      GNUNET_SERVER_notify_transmit_ready (client,
-                                          ntohs(msg->size),
-                                          GNUNET_TIME_UNIT_FOREVER_REL,
-                                          &transmit_callback,
-                                          tcc))
+      (tcc->th = GNUNET_SERVER_notify_transmit_ready (client,
+                                                    ntohs(msg->size),
+                                                    
GNUNET_TIME_UNIT_FOREVER_REL,
+                                                    &transmit_callback,
+                                                     tcc)))
     {
       GNUNET_break (0);
       if (GNUNET_YES == end)
@@ -496,6 +529,9 @@
       GNUNET_free (msg);
       GNUNET_free (tcc);
     }
+  GNUNET_CONTAINER_DLL_insert (tcc_head,
+                              tcc_tail,
+                              tcc);
 }
 
 
@@ -1260,6 +1296,36 @@
 
 
 /**
+ * Function that removes all active reservations made
+ * by the given client and releases the space for other
+ * requests.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ */
+static void
+cleanup_transmits (void *cls,
+                  struct GNUNET_SERVER_Client
+                  * client)
+{
+  struct TransmitCallbackContext *tcc;
+
+  while (NULL != (tcc = tcc_head))
+    {
+      GNUNET_CONTAINER_DLL_remove (tcc_head,
+                                  tcc_tail,
+                                  tcc);
+      if (tcc->th != NULL)
+       GNUNET_CONNECTION_notify_transmit_ready_cancel (tcc->th);
+      GNUNET_free (tcc->msg);
+      GNUNET_free (tcc);
+    }
+
+}
+
+
+
+/**
  * Process datastore requests.
  *
  * @param cls closure
@@ -1323,6 +1389,7 @@
       return;
     }
   GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL);
+  GNUNET_SERVER_disconnect_notify (server, &cleanup_transmits, NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
   expired_kill_task
     = GNUNET_SCHEDULER_add_with_priority (sched,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]