Commit 01568b57 authored by Seppo Takalo's avatar Seppo Takalo Committed by Fabio Baltieri
Browse files

net: coap: Add API to count number of pending requests

Add coap_pendings_count() that return number of waiting
requests on the pendings array.

Signed-off-by: default avatarSeppo Takalo <seppo.takalo@nordicsemi.no>
parent a4356da4
Loading
Loading
Loading
Loading
+9 −0
Changes for include/zephyr/net/coap.h: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1112,6 +1112,15 @@ void coap_pending_clear(struct coap_pending *pending);
 */
void coap_pendings_clear(struct coap_pending *pendings, size_t len);

/**
 * @brief Count number of pending requests.
 *
 * @param len Number of elements in array.
 * @param pendings Array of pending requests.
 * @return count of elements where timeout is not zero.
 */
size_t coap_pendings_count(struct coap_pending *pendings, size_t len);

/**
 * @brief Cancels awaiting for this reply, so it becomes available
 * again. User responsibility to free the memory associated with data.
+13 −0
Changes for subsys/net/lib/coap/coap.c: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1734,6 +1734,19 @@ void coap_pendings_clear(struct coap_pending *pendings, size_t len)
	}
}

size_t coap_pendings_count(struct coap_pending *pendings, size_t len)
{
	struct coap_pending *p = pendings;
	size_t c = 0;

	for (size_t i = 0; i < len && p; i++, p++) {
		if (p->timeout) {
			c++;
		}
	}
	return c;
}

/* Reordering according to RFC7641 section 3.4 but without timestamp comparison */
static inline bool is_newer(int v1, int v2)
{