From c7f52c4c84d6a8898048738c4db9266289c40b45 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 12 Nov 2016 21:25:21 +0100 Subject: wqueue: Reject messges if queue is considered full The write queue was always meant to not queue more than the max_length messages but the implementation never rejected a message. Begin to log and enforce the queue size limit, add a testcase to verify the code and initialize except_cb as part of a fix for that new test case. Real applications might now run into the queue limit and drop messages where they just queued them before. It is unfortunate but I still think it is good to implement the routine as it was intended. We need to review osmo_wqueue_enqueue once more to see that no msgb is leaked. Change-Id: I1e6aef30f3e73d4bcf2967bc49f0783aa65395ae --- src/write_queue.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/write_queue.c') diff --git a/src/write_queue.c b/src/write_queue.c index 3e488aea..c7a43205 100644 --- a/src/write_queue.c +++ b/src/write_queue.c @@ -1,6 +1,6 @@ /* Generic write queue implementation */ /* - * (C) 2010 by Holger Hans Peter Freyther + * (C) 2010-2016 by Holger Hans Peter Freyther * (C) 2010 by On-Waves * * All Rights Reserved @@ -23,6 +23,7 @@ #include #include +#include /*! \addtogroup write_queue * @{ @@ -93,6 +94,7 @@ void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length) queue->current_length = 0; queue->read_cb = NULL; queue->write_cb = NULL; + queue->except_cb = NULL; queue->bfd.cb = osmo_wqueue_bfd_cb; INIT_LLIST_HEAD(&queue->msg_queue); } @@ -104,8 +106,11 @@ void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length) */ int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data) { -// if (queue->current_length + 1 >= queue->max_length) -// LOGP(DMSC, LOGL_ERROR, "The queue is full. Dropping not yet implemented.\n"); + if (queue->current_length >= queue->max_length) { + LOGP(DLGLOBAL, LOGL_ERROR, + "wqueue(%p) is full. Rejecting msgb\n", queue); + return -ENOSPC; + } ++queue->current_length; msgb_enqueue(&queue->msg_queue, data); -- cgit v1.2.3