diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2016-11-12 21:25:21 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2016-12-09 11:37:37 +0100 |
commit | c7f52c4c84d6a8898048738c4db9266289c40b45 (patch) | |
tree | 58277c0a3b93d9e35280e9401de4c12ff434c3ca /src | |
parent | d7c0a373ff38b28a14fd7ee1cc6be3cfbddbd850 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/write_queue.c | 11 |
1 files changed, 8 insertions, 3 deletions
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 <errno.h> #include <osmocom/core/write_queue.h> +#include <osmocom/core/logging.h> /*! \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); |