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:
commit
ff92ec9242
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user