aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-10-16 20:08:07 +0000
committerFlorian Dold <florian.dold@gmail.com>2016-10-16 20:08:07 +0000
commit4a9f4a60c780adce58334d7b083f921c8b7d39ef (patch)
treed95c004ba1398c89c39e2d61a863080c0a941410 /src/util
parentbc57c1cebf65b9d10c97961cc0cd8a7bf166d76e (diff)
downloadgnunet-4a9f4a60c780adce58334d7b083f921c8b7d39ef.tar.gz
gnunet-4a9f4a60c780adce58334d7b083f921c8b7d39ef.zip
Rename MQ_evict to MQ_evacuate and make API nicer
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mq.c65
1 files changed, 36 insertions, 29 deletions
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 */
342void 342void
343GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm) 343GNUNET_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 */
1311void * 1314struct GNUNET_MessageHeader *
1312GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct GNUNET_MessageHeader **msg) 1315GNUNET_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