diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-25 17:39:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-25 17:39:44 +0000 |
commit | 2fa661c71bbfe37518bdefd7561aca475278b86a (patch) | |
tree | 86dda6c5f588441e45671616339b17532d83a013 /src | |
parent | 41f06b9223347f779237d0d56ef8fe9e2d813789 (diff) | |
download | gnunet-2fa661c71bbfe37518bdefd7561aca475278b86a.tar.gz gnunet-2fa661c71bbfe37518bdefd7561aca475278b86a.zip |
add GNUNET_MQ_send_copy
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_mq_lib.h | 12 | ||||
-rw-r--r-- | src/util/mq.c | 29 |
2 files changed, 41 insertions, 0 deletions
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 | |||
@@ -445,6 +445,18 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, | |||
445 | 445 | ||
446 | 446 | ||
447 | /** | 447 | /** |
448 | * Send a copy of a message with the give message queue. | ||
449 | * Can be called repeatedly on the same envelope. | ||
450 | * | ||
451 | * @param mq message queue | ||
452 | * @param ev the envelope with the message to send. | ||
453 | */ | ||
454 | void | ||
455 | GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq, | ||
456 | const struct GNUNET_MQ_Envelope *ev); | ||
457 | |||
458 | |||
459 | /** | ||
448 | * Cancel sending the message. Message must have been sent with | 460 | * Cancel sending the message. Message must have been sent with |
449 | * #GNUNET_MQ_send before. May not be called after the notify sent | 461 | * #GNUNET_MQ_send before. May not be called after the notify sent |
450 | * callback has been called | 462 | * callback has been called |
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 | |||
@@ -310,6 +310,35 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, | |||
310 | 310 | ||
311 | 311 | ||
312 | /** | 312 | /** |
313 | * Send a copy of a message with the give message queue. | ||
314 | * Can be called repeatedly on the same envelope. | ||
315 | * | ||
316 | * @param mq message queue | ||
317 | * @param ev the envelope with the message to send. | ||
318 | */ | ||
319 | void | ||
320 | GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq, | ||
321 | const struct GNUNET_MQ_Envelope *ev) | ||
322 | { | ||
323 | struct GNUNET_MQ_Envelope *env; | ||
324 | uint16_t msize; | ||
325 | |||
326 | msize = ntohs (ev->mh->size); | ||
327 | env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) + | ||
328 | msize); | ||
329 | env->mh = (struct GNUNET_MessageHeader *) &env[1]; | ||
330 | env->sent_cb = ev->sent_cb; | ||
331 | env->sent_cls = ev->sent_cls; | ||
332 | memcpy (&env[1], | ||
333 | ev->mh, | ||
334 | msize); | ||
335 | GNUNET_MQ_send (mq, | ||
336 | env); | ||
337 | } | ||
338 | |||
339 | |||
340 | |||
341 | /** | ||
313 | * Task run to call the send implementation for the next queued | 342 | * Task run to call the send implementation for the next queued |
314 | * message, if any. Only useful for implementing message queues, | 343 | * message, if any. Only useful for implementing message queues, |
315 | * results in undefined behavior if not used carefully. | 344 | * results in undefined behavior if not used carefully. |