net: lwm2m: Handle socket errors

So far socket errors reported by poll/recvfrom were ignored, which could
lead to an unexpected behavior when socket was left in an undefined
state.

Fix this, by requesting a re-registration in the LWM2M state machine,
which will close the faulty socket and open a new one. Note, that simply
closing and re-opening a socket in the lwm2m engine would not work,
since this would silently invalidate any open observations on the
lwm2m server side (due to port number change). Triggering a fresh
registration will notify the server to update its observations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2020-04-29 14:07:48 +02:00 committed by Jukka Rissanen
commit 358dcc1bde
3 changed files with 24 additions and 3 deletions

View file

@ -4114,9 +4114,14 @@ static void socket_receive_loop(void)
}
for (i = 0; i < sock_nfds; i++) {
if (sock_fds[i].revents & POLLERR) {
LOG_ERR("Error in poll.. waiting a moment.");
k_msleep(ENGINE_UPDATE_INTERVAL_MS);
if ((sock_fds[i].revents & POLLERR) ||
(sock_fds[i].revents & POLLNVAL) ||
(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
continue;
}
@ -4133,6 +4138,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
continue;
}