From: Christian Grothoff Date: Mon, 27 Jun 2016 12:20:12 +0000 (+0000) Subject: add function to obtain mq length X-Git-Tag: initial-import-from-subversion-38251~682 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d3834ca8024608b1dc7df467405d8a6ed31e8c05;p=oweals%2Fgnunet.git add function to obtain mq length --- 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 @@ -432,6 +432,16 @@ void GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm); +/** + * Obtain the current length of the message queue. + * + * @param mq queue to inspect + * @return number of queued, non-transmitted messages + */ +unsigned int +GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq); + + /** * Send a message with the give message queue. * May only be called once per message. 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 * @e assoc_map */ uint32_t assoc_id; + + /** + * Number of entries we have in the envelope-DLL. + */ + unsigned int queue_length; }; @@ -264,15 +269,23 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, { if (NULL == mq->error_handler) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "mq: got error %d, but no handler installed\n", - (int) error); + LOG (GNUNET_ERROR_TYPE_WARNING, + "Got error %d, but no handler installed\n", + (int) error); return; } - mq->error_handler (mq->error_handler_cls, error); + mq->error_handler (mq->error_handler_cls, + error); } +/** + * Discard the message queue message, free all + * allocated resources. Must be called in the event + * that a message is created but should not actually be sent. + * + * @param mqm the message to discard + */ void GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm) { @@ -281,6 +294,19 @@ GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm) } +/** + * Obtain the current length of the message queue. + * + * @param mq queue to inspect + * @return number of queued, non-transmitted messages + */ +unsigned int +GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq) +{ + return mq->queue_length; +} + + /** * Send a message with the give message queue. * May only be called once per message. @@ -302,6 +328,7 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, mq->envelope_tail, ev); + mq->queue_length++; return; } mq->current_envelope = ev; @@ -367,6 +394,7 @@ impl_send_continue (void *cls) GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, mq->current_envelope); + mq->queue_length--; mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state); @@ -876,8 +904,10 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq) GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev); + mq->queue_length--; GNUNET_MQ_discard (ev); } + GNUNET_assert (0 == mq->queue_length); if (NULL != mq->current_envelope) { /* we can only discard envelopes that @@ -956,6 +986,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, mq->current_envelope); + mq->queue_length--; mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state); @@ -967,6 +998,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev); + mq->queue_length--; } ev->parent_queue = NULL;