Skip to content

Get number of elements in the queue ? #2397

Discussion options

You must be logged in to vote

Docs fixed, thanks!
We don't have the need to know that, so we did not care. It would require travelling the queue, thing you would actually do anyway when serving msgs.
https://github.com/cesanta/mongoose/blob/master/src/queue.c
_book() checks for room:

mongoose/src/queue.c

Lines 45 to 56 in 57fd93e

size_t mg_queue_book(struct mg_queue *q, char **buf, size_t len) {
size_t space = 0, hs = sizeof(uint32_t) * 2; // *2 is for the 0 marker
if (q->head >= q->tail && q->head + len + hs <= q->size) {
space = q->size - q->head - hs; // There is enough space
} else if (q->head >= q->tail && q->tail > hs) {
mg_queue_write_len(q, 0); // Not enough space ahead
q

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by scaprile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants