Skip to content

Commit f7208bb

Browse files
rerickson1cfriedt
authored andcommitted
net: lwm2m: Add option to force close the connection
Add an option to force close the LwM2M connection instead of always trying to deregister. If on a cellular connection and the connection is dropped, deregistering will never complete and take a long time before retries fail. This option allows the app to close the socket and quickly re-establish the connection when the network connection is available again. Signed-off-by: Ryan Erickson <[email protected]>
1 parent c44eae8 commit f7208bb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

include/net/lwm2m.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,11 @@ void lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name,
995995
*
996996
* @param[in] client_ctx LwM2M context
997997
* @param[in] event_cb Client event callback function
998+
* @param[in] deregister True to deregister the client if registered.
999+
* False to force close the connection.
9981000
*/
9991001
void lwm2m_rd_client_stop(struct lwm2m_ctx *client_ctx,
1000-
lwm2m_ctx_event_cb_t event_cb);
1002+
lwm2m_ctx_event_cb_t event_cb, bool deregister);
10011003

10021004
/**
10031005
* @brief Trigger a Registration Update of the LwM2M RD Client

subsys/net/lib/lwm2m/lwm2m_rd_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,14 +1080,14 @@ void lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name,
10801080
}
10811081

10821082
void lwm2m_rd_client_stop(struct lwm2m_ctx *client_ctx,
1083-
lwm2m_ctx_event_cb_t event_cb)
1083+
lwm2m_ctx_event_cb_t event_cb, bool deregister)
10841084
{
10851085
k_mutex_lock(&client.mutex, K_FOREVER);
10861086

10871087
client.ctx = client_ctx;
10881088
client.event_cb = event_cb;
10891089

1090-
if (sm_is_registered()) {
1090+
if (sm_is_registered() && deregister) {
10911091
set_sm_state(ENGINE_DEREGISTER);
10921092
} else {
10931093
if (client.ctx->sock_fd > -1) {

0 commit comments

Comments
 (0)