Function anj_core_shutdown

Function Documentation

int anj_core_shutdown(anj_t *anj)

Shuts down the Anjay Lite client instance.

This function halts all active LwM2M operations and clears the client’s internal state. Once called, the anj object becomes unusable unless it is reinitialized using anj_core_init.

The following cleanup steps are performed:

  • All queued Send operations are canceled and removed.

  • All observation and attribute storage entries are deleted.

  • Any ongoing LwM2M exchanges (e.g., registration, update, notification, Server-initiated requests) are terminated.

Internally, this function invokes a sequence of operations to tear down networking, including shutting down and closing sockets, and releasing network context state. If any of these steps return ANJ_NET_EAGAIN, indicating that the operation is not yet complete, this function will immediately return that value. In this case, the client is not yet fully shut down, and the function should be called again later to complete the process.

If any networking-related call returns an error other than ANJ_NET_EAGAIN, the client is still fully shut down internally, but some network resources (such as sockets or internal handles) may not have been properly released.

int ret;
do {
    ret = anj_core_shutdown(&anj);
} while (ret == ANJ_NET_EAGAIN);

Note

LwM2M Objects registered via anj_dm_add_obj are user-managed. This function does not free or reset those objects; users are responsible for their manual deallocation if needed.

Note

If blocking behavior is acceptable, the shutdown can be safely handled in a loop:

Warning

If shutdown fails due to networking errors, there is a risk that sockets or system-level resources allocated by the client will not be completely cleaned up. This is especially important in long-running processes or test environments where resource leaks could accumulate.

Parameters:

anj – Pointer to the Anjay client instance to shut down.

Returns:

0 on success, ANJ_NET_EAGAIN if shutdown is still in progress, or a different error code on failure.