1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

Merge pull request #21122 from benpicco/nanocoap_sock/flush

sys/net/nanocoap: flush stale responses before sending request
This commit is contained in:
Marian Buschsieweke 2025-01-06 11:51:46 +00:00 committed by GitHub
commit ff92ec9242
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -195,6 +195,12 @@ static uint32_t _deadline_left_us(uint32_t deadline)
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)
{
@ -223,6 +229,9 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
.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: