Observe: Make sending observe failed messages optional

When a server cleanly closes down (calls coap_free_context()), when
a resource gets deleted, a 4.04 message is sent out (not when using
coap_persist(3)) for any active observe subscriptions. If a server knows it is
going to be restarted, then there is no need to send out a observe failed message.

When deleting a resource when normally running, it is correct to send out a 4.04
Not Found response as the resource has genuinely gone away.  However, when the
server is cleaning shutting down, it is better to use 5.03 Service Unavailable to
indicate the situation may be temporary.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2025-03-28 12:25:05 +00:00
1 parent d38e177af1
commit 1ba3158db8
8 files changed
+58 -10

No files matched your search

+10
View File
@@ -310,6 +310,16 @@ void coap_context_set_session_timeout(coap_context_t *context,
*/
unsigned int coap_context_get_session_timeout(const coap_context_t *context);
/*
* Stop sending out observe subscriptons when calling coap_free_context().
*
* If this is not called, then 5.03 messages are sent out for every observe
* subscription when the context is freed off.
*
* @param context The coap_context_t object.
*/
void coap_context_set_shutdown_no_observe(coap_context_t *context);
/**
* Set the CSM timeout value. The number of seconds to wait for a (TCP) CSM
* negotiation response from the peer.
+3
View File
@@ -193,6 +193,9 @@ struct coap_context_t {
resource */
uint8_t mcast_per_resource; /**< Mcast controlled on a per resource
basis */
uint8_t shutdown_no_send_observe; /**< Do not send out unsolicited observe when
coap_free_context() is called. Otherwise
5.03 will get sent */
#endif /* COAP_SERVER_SUPPORT */
#if COAP_PROXY_SUPPORT
coap_proxy_list_t *proxy_list; /**< Set of active proxy sessions */