diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_mq_lib.h | 12 | ||||
-rw-r--r-- | src/util/mq.c | 65 |
2 files changed, 42 insertions, 35 deletions
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index b339fe0eb..95afb6d75 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h | |||
@@ -415,6 +415,7 @@ struct GNUNET_MQ_MessageHandler | |||
415 | */ | 415 | */ |
416 | struct GNUNET_MQ_Envelope * | 416 | struct GNUNET_MQ_Envelope * |
417 | GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, | 417 | GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, |
418 | |||
418 | uint16_t size, | 419 | uint16_t size, |
419 | uint16_t type); | 420 | uint16_t type); |
420 | 421 | ||
@@ -727,8 +728,7 @@ GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq); | |||
727 | 728 | ||
728 | /** | 729 | /** |
729 | * Get the message that is currently being sent when cancellation of that | 730 | * Get the message that is currently being sent when cancellation of that |
730 | * message is requested. Returns an opaque pointer which contains the memory | 731 | * message is requested. The returned buffer must be freed by the caller. |
731 | * for the message, as well as some control data used by mq. | ||
732 | * | 732 | * |
733 | * This function may be called at most once in the cancel_impl | 733 | * This function may be called at most once in the cancel_impl |
734 | * function of a message queue. | 734 | * function of a message queue. |
@@ -736,11 +736,11 @@ GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq); | |||
736 | * Use this function to avoid copying a half-sent message. | 736 | * Use this function to avoid copying a half-sent message. |
737 | * | 737 | * |
738 | * @param mq message queue | 738 | * @param mq message queue |
739 | * @parem msg pointer to store the message being canceled | 739 | * @return pointer to store the message being canceled, |
740 | * @return memory block that contains the message, must be freed by the caller | 740 | * must be freed by the caller |
741 | */ | 741 | */ |
742 | void * | 742 | struct GNUNET_MessageHeader * |
743 | GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct GNUNET_MessageHeader **msg); | 743 | GNUNET_MQ_impl_cancel_evacuate (struct GNUNET_MQ_Handle *mq); |
744 | 744 | ||
745 | 745 | ||
746 | /** | 746 | /** |
diff --git a/src/util/mq.c b/src/util/mq.c index 6978f662b..81c680e74 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -188,9 +188,9 @@ struct GNUNET_MQ_Handle | |||
188 | unsigned int queue_length; | 188 | unsigned int queue_length; |
189 | 189 | ||
190 | /** | 190 | /** |
191 | * GNUNET_YES if GNUNET_MQ_impl_evict was called. | 191 | * GNUNET_YES if GNUNET_MQ_impl_evacuate was called. |
192 | */ | 192 | */ |
193 | int evict_called; | 193 | int evacuate_called; |
194 | }; | 194 | }; |
195 | 195 | ||
196 | 196 | ||
@@ -340,10 +340,11 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, | |||
340 | * @param mqm the message to discard | 340 | * @param mqm the message to discard |
341 | */ | 341 | */ |
342 | void | 342 | void |
343 | GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm) | 343 | GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *ev) |
344 | { | 344 | { |
345 | GNUNET_assert (NULL == mqm->parent_queue); | 345 | GNUNET_assert (NULL == ev->parent_queue); |
346 | GNUNET_free (mqm); | 346 | /* also frees ev */ |
347 | GNUNET_free (ev->mh); | ||
347 | } | 348 | } |
348 | 349 | ||
349 | 350 | ||
@@ -457,7 +458,8 @@ impl_send_continue (void *cls) | |||
457 | } | 458 | } |
458 | if (NULL != current_envelope->sent_cb) | 459 | if (NULL != current_envelope->sent_cb) |
459 | current_envelope->sent_cb (current_envelope->sent_cls); | 460 | current_envelope->sent_cb (current_envelope->sent_cls); |
460 | GNUNET_free (current_envelope); | 461 | /* also frees current_envelope */ |
462 | GNUNET_free (current_envelope->mh); | ||
461 | } | 463 | } |
462 | 464 | ||
463 | 465 | ||
@@ -588,15 +590,17 @@ GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, | |||
588 | uint16_t size, | 590 | uint16_t size, |
589 | uint16_t type) | 591 | uint16_t type) |
590 | { | 592 | { |
591 | struct GNUNET_MQ_Envelope *mqm; | 593 | struct GNUNET_MQ_Envelope *ev; |
592 | 594 | void *mem; | |
593 | mqm = GNUNET_malloc (sizeof *mqm + size); | 595 | |
594 | mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1]; | 596 | mem = GNUNET_malloc (size + sizeof (struct GNUNET_MQ_Envelope)); |
595 | mqm->mh->size = htons (size); | 597 | ev = mem + size; |
596 | mqm->mh->type = htons (type); | 598 | ev->mh = mem; |
599 | ev->mh->size = htons (size); | ||
600 | ev->mh->type = htons (type); | ||
597 | if (NULL != mhp) | 601 | if (NULL != mhp) |
598 | *mhp = mqm->mh; | 602 | *mhp = ev->mh; |
599 | return mqm; | 603 | return ev; |
600 | } | 604 | } |
601 | 605 | ||
602 | 606 | ||
@@ -1110,7 +1114,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
1110 | GNUNET_assert (NULL != mq); | 1114 | GNUNET_assert (NULL != mq); |
1111 | GNUNET_assert (NULL != mq->cancel_impl); | 1115 | GNUNET_assert (NULL != mq->cancel_impl); |
1112 | 1116 | ||
1113 | mq->evict_called = GNUNET_NO; | 1117 | mq->evacuate_called = GNUNET_NO; |
1114 | 1118 | ||
1115 | if (mq->current_envelope == ev) | 1119 | if (mq->current_envelope == ev) |
1116 | { | 1120 | { |
@@ -1146,11 +1150,11 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
1146 | mq->queue_length--; | 1150 | mq->queue_length--; |
1147 | } | 1151 | } |
1148 | 1152 | ||
1149 | if (GNUNET_YES != mq->evict_called) | 1153 | if (GNUNET_YES != mq->evacuate_called) |
1150 | { | 1154 | { |
1151 | ev->parent_queue = NULL; | 1155 | ev->parent_queue = NULL; |
1152 | ev->mh = NULL; | 1156 | /* also frees ev */ |
1153 | GNUNET_free (ev); | 1157 | GNUNET_free (ev->mh); |
1154 | } | 1158 | } |
1155 | } | 1159 | } |
1156 | 1160 | ||
@@ -1296,8 +1300,7 @@ GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh | |||
1296 | 1300 | ||
1297 | /** | 1301 | /** |
1298 | * Get the message that is currently being sent when cancellation of that | 1302 | * Get the message that is currently being sent when cancellation of that |
1299 | * message is requested. Returns an opaque pointer which contains the memory | 1303 | * message is requested. The returned buffer must be freed by the caller. |
1300 | * for the message, as well as some control data used by mq. | ||
1301 | * | 1304 | * |
1302 | * This function may be called at most once in the cancel_impl | 1305 | * This function may be called at most once in the cancel_impl |
1303 | * function of a message queue. | 1306 | * function of a message queue. |
@@ -1305,19 +1308,23 @@ GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh | |||
1305 | * Use this function to avoid copying a half-sent message. | 1308 | * Use this function to avoid copying a half-sent message. |
1306 | * | 1309 | * |
1307 | * @param mq message queue | 1310 | * @param mq message queue |
1308 | * @parem msg pointer to store the message being canceled | 1311 | * @return pointer to store the message being canceled, |
1309 | * @return memory block that contains the message, must be freed by the caller | 1312 | * must be freed by the caller |
1310 | */ | 1313 | */ |
1311 | void * | 1314 | struct GNUNET_MessageHeader * |
1312 | GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct GNUNET_MessageHeader **msg) | 1315 | GNUNET_MQ_impl_cancel_evacuate (struct GNUNET_MQ_Handle *mq) |
1313 | { | 1316 | { |
1314 | GNUNET_assert (GNUNET_NO == mq->evict_called); | 1317 | struct GNUNET_MessageHeader *mh; |
1318 | |||
1319 | GNUNET_assert (GNUNET_NO == mq->evacuate_called); | ||
1315 | GNUNET_assert (NULL != mq->current_envelope); | 1320 | GNUNET_assert (NULL != mq->current_envelope); |
1316 | mq->evict_called = GNUNET_YES; | 1321 | |
1322 | mq->evacuate_called = GNUNET_YES; | ||
1323 | mh = mq->current_envelope->mh; | ||
1317 | mq->current_envelope->parent_queue = NULL; | 1324 | mq->current_envelope->parent_queue = NULL; |
1318 | mq->current_envelope->mh = NULL; | 1325 | mq->current_envelope = NULL; |
1319 | *msg = mq->current_envelope->mh; | 1326 | |
1320 | return mq->current_envelope; | 1327 | return mh; |
1321 | } | 1328 | } |
1322 | 1329 | ||
1323 | 1330 | ||