gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r30749 - in gnunet/src: conversation util


From: gnunet
Subject: [GNUnet-SVN] r30749 - in gnunet/src: conversation util
Date: Sat, 16 Nov 2013 18:51:32 +0100

Author: grothoff
Date: 2013-11-16 18:51:32 +0100 (Sat, 16 Nov 2013)
New Revision: 30749

Modified:
   gnunet/src/conversation/conversation_api.c
   gnunet/src/util/mq.c
Log:
-avoid possible problem due to clean up during deeper recursion by making 
continuation asynchronous

Modified: gnunet/src/conversation/conversation_api.c
===================================================================
--- gnunet/src/conversation/conversation_api.c  2013-11-16 17:41:13 UTC (rev 
30748)
+++ gnunet/src/conversation/conversation_api.c  2013-11-16 17:51:32 UTC (rev 
30749)
@@ -261,7 +261,7 @@
   if (NULL == label)
     name = GNUNET_strdup (GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id));
   else
-    GNUNET_asprintf (&name, "%.gnu", label);
+    GNUNET_asprintf (&name, "%s.gnu", label);
   caller->caller_id_str = name;
   caller->state = CS_RINGING;
   phone->event_handler (phone->event_handler_cls,

Modified: gnunet/src/util/mq.c
===================================================================
--- gnunet/src/util/mq.c        2013-11-16 17:41:13 UTC (rev 30748)
+++ gnunet/src/util/mq.c        2013-11-16 17:51:32 UTC (rev 30749)
@@ -126,6 +126,11 @@
   struct GNUNET_CONTAINER_MultiHashMap32 *assoc_map;
 
   /**
+   * Task scheduled during #GNUNET_MQ_impl_send_continue.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier continue_task;
+
+  /**
    * Next id that should be used for the assoc_map,
    * initialized lazily to a random value together with
    * assoc_map
@@ -249,18 +254,21 @@
 
 
 /**
- * Call the send implementation for the next queued message,
- * if any.
- * Only useful for implementing message queues,
+ * Task run to call the send implementation for the next queued
+ * message, if any.  Only useful for implementing message queues,
  * results in undefined behavior if not used carefully.
  *
- * @param mq message queue to send the next message with
+ * @param cls message queue to send the next message with
+ * @param tc scheduler context
  */
-void
-GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
+static void
+impl_send_continue (void *cls,
+                    const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  struct GNUNET_MQ_Handle *mq = cls;
   struct GNUNET_MQ_Envelope *current_envelope;
 
+  mq->continue_task = GNUNET_SCHEDULER_NO_TASK;
   /* call is only valid if we're actually currently sending
    * a message */
   current_envelope = mq->current_envelope;
@@ -284,6 +292,23 @@
 
 
 /**
+ * Call the send implementation for the next queued message,
+ * if any.
+ * Only useful for implementing message queues,
+ * results in undefined behavior if not used carefully.
+ *
+ * @param mq message queue to send the next message with
+ */
+void
+GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
+{
+  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == mq->continue_task);
+  mq->continue_task = GNUNET_SCHEDULER_add_now (&impl_send_continue,
+                                                mq);
+}
+
+
+/**
  * Create a message queue for the specified handlers.
  *
  * @param send function the implements sending messages
@@ -435,7 +460,6 @@
 }
 
 
-
 static void
 server_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
                             void *impl_state)
@@ -448,6 +472,7 @@
   GNUNET_free (state);
 }
 
+
 static void
 server_client_send_impl (struct GNUNET_MQ_Handle *mq,
                          const struct GNUNET_MessageHeader *msg, void 
*impl_state)
@@ -513,13 +538,14 @@
  * Transmit a queued message to the session's client.
  *
  * @param cls consensus session
- * @param size number of bytes available in buf
+ * @param size number of bytes available in @a buf
  * @param buf where the callee should write the message
  * @return number of bytes written to buf
  */
 static size_t
-connection_client_transmit_queued (void *cls, size_t size,
-                 void *buf)
+connection_client_transmit_queued (void *cls,
+                                   size_t size,
+                                   void *buf)
 {
   struct GNUNET_MQ_Handle *mq = cls;
   const struct GNUNET_MessageHeader *msg;
@@ -555,13 +581,13 @@
 }
 
 
-
 static void
 connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
 {
   GNUNET_free (impl_state);
 }
 
+
 static void
 connection_client_send_impl (struct GNUNET_MQ_Handle *mq,
                              const struct GNUNET_MessageHeader *msg, void 
*impl_state)
@@ -641,7 +667,6 @@
 }
 
 
-
 void *
 GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
 {
@@ -681,7 +706,11 @@
   {
     mq->destroy_impl (mq, mq->impl_state);
   }
-
+  if (GNUNET_SCHEDULER_NO_TASK != mq->continue_task)
+  {
+    GNUNET_SCHEDULER_cancel (mq->continue_task);
+    mq->continue_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   while (NULL != mq->envelope_head)
   {
     struct GNUNET_MQ_Envelope *ev;




reply via email to

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