diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_mq_lib.h | 10 | ||||
-rw-r--r-- | src/util/mq.c | 40 |
2 files changed, 46 insertions, 4 deletions
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index 0d201d36d..08e09d5b5 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h | |||
@@ -433,6 +433,16 @@ GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm); | |||
433 | 433 | ||
434 | 434 | ||
435 | /** | 435 | /** |
436 | * Obtain the current length of the message queue. | ||
437 | * | ||
438 | * @param mq queue to inspect | ||
439 | * @return number of queued, non-transmitted messages | ||
440 | */ | ||
441 | unsigned int | ||
442 | GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq); | ||
443 | |||
444 | |||
445 | /** | ||
436 | * Send a message with the give message queue. | 446 | * Send a message with the give message queue. |
437 | * May only be called once per message. | 447 | * May only be called once per message. |
438 | * | 448 | * |
diff --git a/src/util/mq.c b/src/util/mq.c index b84db002a..917f4566e 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -140,6 +140,11 @@ struct GNUNET_MQ_Handle | |||
140 | * @e assoc_map | 140 | * @e assoc_map |
141 | */ | 141 | */ |
142 | uint32_t assoc_id; | 142 | uint32_t assoc_id; |
143 | |||
144 | /** | ||
145 | * Number of entries we have in the envelope-DLL. | ||
146 | */ | ||
147 | unsigned int queue_length; | ||
143 | }; | 148 | }; |
144 | 149 | ||
145 | 150 | ||
@@ -264,15 +269,23 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, | |||
264 | { | 269 | { |
265 | if (NULL == mq->error_handler) | 270 | if (NULL == mq->error_handler) |
266 | { | 271 | { |
267 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 272 | LOG (GNUNET_ERROR_TYPE_WARNING, |
268 | "mq: got error %d, but no handler installed\n", | 273 | "Got error %d, but no handler installed\n", |
269 | (int) error); | 274 | (int) error); |
270 | return; | 275 | return; |
271 | } | 276 | } |
272 | mq->error_handler (mq->error_handler_cls, error); | 277 | mq->error_handler (mq->error_handler_cls, |
278 | error); | ||
273 | } | 279 | } |
274 | 280 | ||
275 | 281 | ||
282 | /** | ||
283 | * Discard the message queue message, free all | ||
284 | * allocated resources. Must be called in the event | ||
285 | * that a message is created but should not actually be sent. | ||
286 | * | ||
287 | * @param mqm the message to discard | ||
288 | */ | ||
276 | void | 289 | void |
277 | GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm) | 290 | GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm) |
278 | { | 291 | { |
@@ -282,6 +295,19 @@ GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm) | |||
282 | 295 | ||
283 | 296 | ||
284 | /** | 297 | /** |
298 | * Obtain the current length of the message queue. | ||
299 | * | ||
300 | * @param mq queue to inspect | ||
301 | * @return number of queued, non-transmitted messages | ||
302 | */ | ||
303 | unsigned int | ||
304 | GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq) | ||
305 | { | ||
306 | return mq->queue_length; | ||
307 | } | ||
308 | |||
309 | |||
310 | /** | ||
285 | * Send a message with the give message queue. | 311 | * Send a message with the give message queue. |
286 | * May only be called once per message. | 312 | * May only be called once per message. |
287 | * | 313 | * |
@@ -302,6 +328,7 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, | |||
302 | GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, | 328 | GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, |
303 | mq->envelope_tail, | 329 | mq->envelope_tail, |
304 | ev); | 330 | ev); |
331 | mq->queue_length++; | ||
305 | return; | 332 | return; |
306 | } | 333 | } |
307 | mq->current_envelope = ev; | 334 | mq->current_envelope = ev; |
@@ -367,6 +394,7 @@ impl_send_continue (void *cls) | |||
367 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, | 394 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
368 | mq->envelope_tail, | 395 | mq->envelope_tail, |
369 | mq->current_envelope); | 396 | mq->current_envelope); |
397 | mq->queue_length--; | ||
370 | mq->send_impl (mq, | 398 | mq->send_impl (mq, |
371 | mq->current_envelope->mh, | 399 | mq->current_envelope->mh, |
372 | mq->impl_state); | 400 | mq->impl_state); |
@@ -876,8 +904,10 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq) | |||
876 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, | 904 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
877 | mq->envelope_tail, | 905 | mq->envelope_tail, |
878 | ev); | 906 | ev); |
907 | mq->queue_length--; | ||
879 | GNUNET_MQ_discard (ev); | 908 | GNUNET_MQ_discard (ev); |
880 | } | 909 | } |
910 | GNUNET_assert (0 == mq->queue_length); | ||
881 | if (NULL != mq->current_envelope) | 911 | if (NULL != mq->current_envelope) |
882 | { | 912 | { |
883 | /* we can only discard envelopes that | 913 | /* we can only discard envelopes that |
@@ -956,6 +986,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
956 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, | 986 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
957 | mq->envelope_tail, | 987 | mq->envelope_tail, |
958 | mq->current_envelope); | 988 | mq->current_envelope); |
989 | mq->queue_length--; | ||
959 | mq->send_impl (mq, | 990 | mq->send_impl (mq, |
960 | mq->current_envelope->mh, | 991 | mq->current_envelope->mh, |
961 | mq->impl_state); | 992 | mq->impl_state); |
@@ -967,6 +998,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
967 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, | 998 | GNUNET_CONTAINER_DLL_remove (mq->envelope_head, |
968 | mq->envelope_tail, | 999 | mq->envelope_tail, |
969 | ev); | 1000 | ev); |
1001 | mq->queue_length--; | ||
970 | } | 1002 | } |
971 | 1003 | ||
972 | ev->parent_queue = NULL; | 1004 | ev->parent_queue = NULL; |