gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r38157 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r38157 - in gnunet/src: include util
Date: Sun, 16 Oct 2016 21:13:45 +0200

Author: dold
Date: 2016-10-16 21:13:45 +0200 (Sun, 16 Oct 2016)
New Revision: 38157

Modified:
   gnunet/src/include/gnunet_mq_lib.h
   gnunet/src/util/mq.c
Log:
Add evict functionalty to mq cancellation.

Useful to avoid copying of buffers when canceling a
partially sent message.


Modified: gnunet/src/include/gnunet_mq_lib.h
===================================================================
--- gnunet/src/include/gnunet_mq_lib.h  2016-10-13 07:44:31 UTC (rev 38156)
+++ gnunet/src/include/gnunet_mq_lib.h  2016-10-16 19:13:45 UTC (rev 38157)
@@ -726,6 +726,24 @@
 
 
 /**
+ * Get the message that is currently being sent when cancellation of that
+ * message is requested.  Returns an opaque pointer which contains the memory
+ * for the message, as well as some control data used by mq.
+ *
+ * This function may be called at most once in the cancel_impl
+ * function of a message queue.
+ *
+ * Use this function to avoid copying a half-sent message.
+ *
+ * @param mq message queue
+ * @parem msg pointer to store the message being canceled
+ * @return memory block that contains the message, must be freed by the caller
+ */
+void *
+GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct 
GNUNET_MessageHeader **msg);
+
+
+/**
  * Get the implementation state associated with the
  * message queue.
  *

Modified: gnunet/src/util/mq.c
===================================================================
--- gnunet/src/util/mq.c        2016-10-13 07:44:31 UTC (rev 38156)
+++ gnunet/src/util/mq.c        2016-10-16 19:13:45 UTC (rev 38157)
@@ -82,7 +82,6 @@
    * Did the application call #GNUNET_MQ_env_set_options()?
    */
   int have_custom_options;
-
 };
 
 
@@ -187,6 +186,11 @@
    * Number of entries we have in the envelope-DLL.
    */
   unsigned int queue_length;
+
+  /**
+   * GNUNET_YES if GNUNET_MQ_impl_evict was called.
+   */
+  int evict_called;
 };
 
 
@@ -1105,6 +1109,8 @@
 
   GNUNET_assert (NULL != mq);
   GNUNET_assert (NULL != mq->cancel_impl);
+  
+  mq->evict_called = GNUNET_NO;
 
   if (mq->current_envelope == ev)
   {
@@ -1140,9 +1146,12 @@
     mq->queue_length--;
   }
 
-  ev->parent_queue = NULL;
-  ev->mh = NULL;
-  GNUNET_free (ev);
+  if (GNUNET_YES != mq->evict_called)
+  {
+    ev->parent_queue = NULL;
+    ev->mh = NULL;
+    GNUNET_free (ev);
+  }
 }
 
 
@@ -1285,4 +1294,31 @@
 }
 
 
+/**
+ * Get the message that is currently being sent when cancellation of that
+ * message is requested.  Returns an opaque pointer which contains the memory
+ * for the message, as well as some control data used by mq.
+ *
+ * This function may be called at most once in the cancel_impl
+ * function of a message queue.
+ *
+ * Use this function to avoid copying a half-sent message.
+ *
+ * @param mq message queue
+ * @parem msg pointer to store the message being canceled
+ * @return memory block that contains the message, must be freed by the caller
+ */
+void *
+GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct 
GNUNET_MessageHeader **msg)
+{
+  GNUNET_assert (GNUNET_NO == mq->evict_called);
+  GNUNET_assert (NULL != mq->current_envelope);
+  mq->evict_called = GNUNET_YES;
+  mq->current_envelope->parent_queue = NULL;
+  mq->current_envelope->mh = NULL;
+  *msg = mq->current_envelope->mh;
+  return mq->current_envelope;
+}
+
+
 /* end of mq.c */




reply via email to

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