GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq);
+/**
+ * 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.
* Did the application call #GNUNET_MQ_env_set_options()?
*/
int have_custom_options;
-
};
* 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;
};
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL != mq->cancel_impl);
+
+ mq->evict_called = GNUNET_NO;
if (mq->current_envelope == ev)
{
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);
+ }
}
}
+/**
+ * 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 */