Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/net/nanocoap: flush stale responses before sending request #21122

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sys/net/application_layer/nanocoap/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@
return deadline - now;
}

static void _sock_flush(nanocoap_sock_t *sock)
{
void *payload, *ctx = NULL;
while (_sock_recv_buf(sock, &payload, &ctx, 0) > 0 || ctx) {}
}

ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
coap_request_cb_t cb, void *arg)
{
Expand All @@ -207,7 +213,7 @@

/* random timeout, deadline for receive retries */
uint32_t timeout = random_uint32_range((uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS * US_PER_MS,
(uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS * CONFIG_COAP_RANDOM_FACTOR_1000);

Check warning on line 216 in sys/net/application_layer/nanocoap/sock.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
uint32_t deadline = _deadline_from_interval(timeout);

/* check if we expect a reply */
Expand All @@ -223,6 +229,9 @@
.iol_len = coap_get_total_len(pkt),
};

/* clear out stale responses from previous requests */
_sock_flush(sock);

while (1) {
switch (state) {
case STATE_REQUEST_SEND:
Expand Down
Loading