From 45958a441ac5eeca095c154481d70de68cf4c999 Mon Sep 17 00:00:00 2001 From: Martino Ferrari Date: Thu, 8 Oct 2026 17:44:13 +0200 Subject: [PATCH] docs: late_resequenced counts held-then-delivered packets, not gaps avoided Fix the false trailing clause in the udps_stats_t::late_resequenced comment, move udps_held_t from the tunable-limits section to internal-state next to udps_slot_t, and add braces to three braceless if bodies to match house style. Co-Authored-By: Claude Sonnet 4.6 --- deps/udpsclient/udps_client.c | 25 +++++++++++++------------ deps/udpsclient/udps_client.h | 8 ++++++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/deps/udpsclient/udps_client.c b/deps/udpsclient/udps_client.c index cc72595..585b01e 100644 --- a/deps/udpsclient/udps_client.c +++ b/deps/udpsclient/udps_client.c @@ -38,15 +38,6 @@ /** Total bytes the reorder ring may hold, so a fast stream cannot grow it without bound. */ #define UDPS_REORDER_BYTES (4u * 1024u * 1024u) -typedef struct { - uint8_t *buf; /**< owned; grown on demand to the payload's length */ - size_t cap; - size_t len; - uint32_t counter; - double recv_time; - int used; -} udps_held_t; - /** Concurrent in-flight reassemblies. The server interleaves at most a couple. */ #define UDPS_MAX_SLOTS 4 @@ -165,6 +156,16 @@ typedef struct { double first_seen; } udps_slot_t; +/** One slot in the reorder ring: a raw payload held until its counter is next. */ +typedef struct { + uint8_t *buf; /**< owned; grown on demand to the payload's length */ + size_t cap; + size_t len; + uint32_t counter; + double recv_time; + int used; +} udps_held_t; + struct udps_client { udps_client_config_t cfg; /* Owned copies: the caller's strings need not outlive the create call. */ @@ -747,7 +748,7 @@ static int order_data(udps_client_t *c, const uint8_t *pl, size_t len, if (delta == 0) { int rc = deliver_data(c, pl, len, counter, recv_time, 0u, 0); c->next_counter = counter + 1u; - if (rc == 0) rc = drain_held(c, 0u); + if (rc == 0) { rc = drain_held(c, 0u); } return rc; } if (delta > 0) { @@ -1364,8 +1365,8 @@ int udps_client_poll(udps_client_t *c, int timeout_ms) { * the next arrival is 100 ms away, which is five times the whole budget. */ if (c->gap_deadline > 0.0) { double left = c->gap_deadline - now_wall(); - if (left < 0.0) left = 0.0; - if (left < budget) budget = left; + if (left < 0.0) { left = 0.0; } + if (left < budget) { budget = left; } } FD_ZERO(&rset); diff --git a/deps/udpsclient/udps_client.h b/deps/udpsclient/udps_client.h index 92ff0ef..82c6a5d 100644 --- a/deps/udpsclient/udps_client.h +++ b/deps/udpsclient/udps_client.h @@ -188,8 +188,12 @@ typedef struct { */ uint64_t stale_packets; /** - * DATA packets that arrived out of order and were put *back* in order inside - * the reorder window, so the consumer never saw a gap for them. + * DATA packets that were held waiting for an earlier counter and subsequently + * delivered via @c drain_held(). This includes a packet released by the + * reorder window expiring: that packet arrives alongside a non-zero @c lost + * and therefore alongside a gap, so @c late_resequenced is not by itself a + * count of gaps avoided. Compare @c late_delivered, which counts packets + * that lost the race past an already-expired window entirely. */ uint64_t late_resequenced; /**