From c562b6cbe91c87d4ec49f2cf7d3b14d01590660b Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 10 Jan 2025 21:25:34 +0100 Subject: [PATCH] Revert "sock/udp: work around gnrc_sock_recv() returning early timeout" This reverts commit e3d00682bcad2e0f26ee15b1c73d5da022b18786, which added a work around for two bugs: - ztimer triggering too early (fixed in https://github.com/RIOT-OS/RIOT/pull/20924) - gnrc_sock_recv() returning when an old "timeout" message is still in the message queue (fixed in https://github.com/RIOT-OS/RIOT/pull/21113) With those bugs fixed, the work around should not longer be needed. --- sys/net/gnrc/sock/udp/gnrc_sock_udp.c | 31 +-------------------------- 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/sys/net/gnrc/sock/udp/gnrc_sock_udp.c b/sys/net/gnrc/sock/udp/gnrc_sock_udp.c index d6c59b471a3e..0e494525a2b3 100644 --- a/sys/net/gnrc/sock/udp/gnrc_sock_udp.c +++ b/sys/net/gnrc/sock/udp/gnrc_sock_udp.c @@ -239,16 +239,6 @@ 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) @@ -286,26 +276,7 @@ ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx, _aux.rssi = &aux->rssi; } #endif - 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; - } - + res = gnrc_sock_recv((gnrc_sock_reg_t *)sock, &pkt, timeout, &tmp, &_aux); if (res < 0) { return res; }