net: lwm2m: Add a callback to notify socket errors to engine users

Currently, when socket errors occur during receive, the LwM2M engine
restarts the state machine and registers again to the server. While this
works in simple use case (only RD client socket open), it's not a valid
approach when more sockets are open (FW update socket).

Fix this by introducing socket fault callback, which is registered by
the LwM2M engine users. This way, a proper socket owner is notified on
error and can pertake appropriate action.

For RD socket errors the behaviour remains the same - the state machine
is reset and the client registers again to the server. For FW update
socket, handle the error by reopening the socket and retransmitting the
last request. This allows to resume the download from the point the
error occured, w/o a need to start from scratch.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2020-11-03 14:04:44 +01:00 committed by Carles Cufí
commit 397b2a71fa
5 changed files with 52 additions and 8 deletions

View file

@ -4234,9 +4234,10 @@ static void socket_receive_loop(void)
(sock_fds[i].revents & POLLHUP)) {
LOG_ERR("Poll reported a socket error, %02x.",
sock_fds[i].revents);
#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT)
engine_trigger_restart();
#endif
if (sock_ctx[i] != NULL &&
sock_ctx[i]->fault_cb != NULL) {
sock_ctx[i]->fault_cb(EIO);
}
continue;
}
@ -4254,9 +4255,9 @@ static void socket_receive_loop(void)
if (len < 0) {
LOG_ERR("Error reading response: %d", errno);
#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT)
engine_trigger_restart();
#endif
if (sock_ctx[i]->fault_cb != NULL) {
sock_ctx[i]->fault_cb(errno);
}
continue;
}