From 97ab322f8da5ff74ddc704b5f7ba1ff6a1c81e00 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 3 May 2025 11:46:00 +0100 Subject: [PATCH] coap-client.c: Adjust wait timeouts based on observe and multicast --- examples/coap-client.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/coap-client.c b/examples/coap-client.c index 919287f7..90ae4ced 100644 --- a/examples/coap-client.c +++ b/examples/coap-client.c @@ -2030,12 +2030,23 @@ main(int argc, char **argv) { goto failed; } - if (is_mcast && wait_seconds == DEFAULT_WAIT_TIME) - /* Allow for other servers to respond within DEFAULT_LEISURE RFC7252 8.2 */ - wait_seconds = coap_session_get_default_leisure(session).integer_part + 1; + if (wait_seconds == DEFAULT_WAIT_TIME) { + /* Adjust wait time if needed */ + if (is_mcast) { + /* Allow for other servers to respond within DEFAULT_LEISURE RFC7252 8.2 */ + int mcast_respond = coap_session_get_default_leisure(session).integer_part + 1; - if (obs_seconds > wait_seconds && wait_seconds == DEFAULT_WAIT_TIME) - wait_seconds = obs_seconds; + if (!doing_observe) { + wait_seconds = mcast_respond; + } else { + /* Allow for observe set up and tear down time and mcast potential delay*/ + wait_seconds = obs_seconds + 5 + mcast_respond; + } + } else if (doing_observe) { + /* Allow for observe set up and tear down time */ + wait_seconds = obs_seconds + 5; + } + } wait_ms = wait_seconds * 1000; coap_log_debug("timeout is set to %u seconds\n", wait_seconds);