From 2fa661c71bbfe37518bdefd7561aca475278b86a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 25 Jun 2016 17:39:44 +0000 Subject: [PATCH] add GNUNET_MQ_send_copy --- src/include/gnunet_mq_lib.h | 12 ++++++++++++ src/util/mq.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index 7bcaa7efc..0d201d36d 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h @@ -444,6 +444,18 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev); +/** + * Send a copy of a message with the give message queue. + * Can be called repeatedly on the same envelope. + * + * @param mq message queue + * @param ev the envelope with the message to send. + */ +void +GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MQ_Envelope *ev); + + /** * Cancel sending the message. Message must have been sent with * #GNUNET_MQ_send before. May not be called after the notify sent diff --git a/src/util/mq.c b/src/util/mq.c index fb679c18d..b84db002a 100644 --- a/src/util/mq.c +++ b/src/util/mq.c @@ -309,6 +309,35 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, } +/** + * Send a copy of a message with the give message queue. + * Can be called repeatedly on the same envelope. + * + * @param mq message queue + * @param ev the envelope with the message to send. + */ +void +GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq, + const struct GNUNET_MQ_Envelope *ev) +{ + struct GNUNET_MQ_Envelope *env; + uint16_t msize; + + msize = ntohs (ev->mh->size); + env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) + + msize); + env->mh = (struct GNUNET_MessageHeader *) &env[1]; + env->sent_cb = ev->sent_cb; + env->sent_cls = ev->sent_cls; + memcpy (&env[1], + ev->mh, + msize); + GNUNET_MQ_send (mq, + env); +} + + + /** * Task run to call the send implementation for the next queued * message, if any. Only useful for implementing message queues, -- 2.25.1