mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #19965 from benpicco/sock_udp_recv-ealry
sock/udp: work around gnrc_sock_recv() returning early timeout
This commit is contained in:
commit
db6d918c46
@ -25,6 +25,8 @@ BOARD_INSUFFICIENT_MEMORY := \
|
||||
olimex-msp430-h1611 \
|
||||
olimex-msp430-h2618 \
|
||||
samd10-xmini \
|
||||
saml10-xpro \
|
||||
saml11-xpro \
|
||||
slstk3400a \
|
||||
stk3200 \
|
||||
stm32f030f4-demo \
|
||||
|
@ -237,6 +237,16 @@ static bool _accept_remote(const sock_udp_t *sock, const udp_hdr_t *hdr,
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t _now_us(void)
|
||||
{
|
||||
#ifdef MODULE_ZTIMER_USEC
|
||||
return ztimer_now(ZTIMER_USEC);
|
||||
#endif
|
||||
#ifdef MODULE_ZTIMER_MSEC
|
||||
return ztimer_now(ZTIMER_MSEC) * US_PER_MS;
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
|
||||
uint32_t timeout, sock_udp_ep_t *remote,
|
||||
sock_udp_aux_rx_t *aux)
|
||||
@ -274,7 +284,26 @@ ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
|
||||
_aux.rssi = &aux->rssi;
|
||||
}
|
||||
#endif
|
||||
res = gnrc_sock_recv((gnrc_sock_reg_t *)sock, &pkt, timeout, &tmp, &_aux);
|
||||
unsigned now = _now_us();
|
||||
while (1) {
|
||||
res = gnrc_sock_recv((gnrc_sock_reg_t *)sock, &pkt, timeout, &tmp, &_aux);
|
||||
|
||||
if (res != -ETIMEDOUT) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* HACK: gnrc_sock_recv() sometimes returns -ETIMEDOUT too early */
|
||||
uint32_t time_elapsed = _now_us() - now;
|
||||
if (time_elapsed < (timeout - timeout/10)) {
|
||||
DEBUG("gnrc_sock_udp: timeout happened %"PRIu32" µs early\n",
|
||||
timeout - time_elapsed);
|
||||
timeout -= time_elapsed;
|
||||
now = _now_us();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user