*/
struct GNUNET_MQ_Envelope *
GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp,
+
uint16_t size,
uint16_t type);
/**
* 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.
+ * message is requested. The returned buffer must be freed by the caller.
*
* 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
+ * @return pointer to store the message being canceled,
+ * must be freed by the caller
*/
-void *
-GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct GNUNET_MessageHeader **msg);
+struct GNUNET_MessageHeader *
+GNUNET_MQ_impl_cancel_evacuate (struct GNUNET_MQ_Handle *mq);
/**
unsigned int queue_length;
/**
- * GNUNET_YES if GNUNET_MQ_impl_evict was called.
+ * GNUNET_YES if GNUNET_MQ_impl_evacuate was called.
*/
- int evict_called;
+ int evacuate_called;
};
* @param mqm the message to discard
*/
void
-GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm)
+GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *ev)
{
- GNUNET_assert (NULL == mqm->parent_queue);
- GNUNET_free (mqm);
+ GNUNET_assert (NULL == ev->parent_queue);
+ /* also frees ev */
+ GNUNET_free (ev->mh);
}
}
if (NULL != current_envelope->sent_cb)
current_envelope->sent_cb (current_envelope->sent_cls);
- GNUNET_free (current_envelope);
+ /* also frees current_envelope */
+ GNUNET_free (current_envelope->mh);
}
uint16_t size,
uint16_t type)
{
- struct GNUNET_MQ_Envelope *mqm;
-
- mqm = GNUNET_malloc (sizeof *mqm + size);
- mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
- mqm->mh->size = htons (size);
- mqm->mh->type = htons (type);
+ struct GNUNET_MQ_Envelope *ev;
+ void *mem;
+
+ mem = GNUNET_malloc (size + sizeof (struct GNUNET_MQ_Envelope));
+ ev = mem + size;
+ ev->mh = mem;
+ ev->mh->size = htons (size);
+ ev->mh->type = htons (type);
if (NULL != mhp)
- *mhp = mqm->mh;
- return mqm;
+ *mhp = ev->mh;
+ return ev;
}
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL != mq->cancel_impl);
- mq->evict_called = GNUNET_NO;
+ mq->evacuate_called = GNUNET_NO;
if (mq->current_envelope == ev)
{
mq->queue_length--;
}
- if (GNUNET_YES != mq->evict_called)
+ if (GNUNET_YES != mq->evacuate_called)
{
ev->parent_queue = NULL;
- ev->mh = NULL;
- GNUNET_free (ev);
+ /* also frees ev */
+ GNUNET_free (ev->mh);
}
}
/**
* 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.
+ * message is requested. The returned buffer must be freed by the caller.
*
* 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
+ * @return pointer to store the message being canceled,
+ * must be freed by the caller
*/
-void *
-GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct GNUNET_MessageHeader **msg)
+struct GNUNET_MessageHeader *
+GNUNET_MQ_impl_cancel_evacuate (struct GNUNET_MQ_Handle *mq)
{
- GNUNET_assert (GNUNET_NO == mq->evict_called);
+ struct GNUNET_MessageHeader *mh;
+
+ GNUNET_assert (GNUNET_NO == mq->evacuate_called);
GNUNET_assert (NULL != mq->current_envelope);
- mq->evict_called = GNUNET_YES;
+
+ mq->evacuate_called = GNUNET_YES;
+ mh = mq->current_envelope->mh;
mq->current_envelope->parent_queue = NULL;
- mq->current_envelope->mh = NULL;
- *msg = mq->current_envelope->mh;
- return mq->current_envelope;
+ mq->current_envelope = NULL;
+
+ return mh;
}