1.1. In function: poll (fds, ARRAY_SIZE (fds),
cloud_keepalive_time_left (cloud_backend) );
How to detect actions that perform socket disconnections locally.
while (true) {
ret = poll(fds, ARRAY_SIZE(fds),
cloud_keepalive_time_left(cloud_backend));
if (ret < 0) {
LOG_ERR("poll() returned an error: %d", ret);
error_handler(ERROR_CLOUD, ret);
continue;
}
if (ret == 0) {
cloud_ping(cloud_backend);
continue;
}
if ((fds[0].revents & POLLIN) == POLLIN) {
cloud_input(cloud_backend);
}
if ((fds[0].revents & POLLNVAL) == POLLNVAL) {
if (atomic_get(&reconnect_to_cloud)) {
k_delayed_work_cancel(&cloud_reboot_work);
LOG_INF("Attempting reconnect...");
goto connect;
}
LOG_ERR("Socket error: POLLNVAL");
LOG_ERR("The cloud socket was unexpectedly closed.");
error_handler(ERROR_CLOUD, -EIO);
return;
}
if ((fds[0].revents & POLLHUP) == POLLHUP) {
LOG_ERR("Socket error: POLLHUP");
LOG_ERR("Connection was closed by the cloud.");
error_handler(ERROR_CLOUD, -EIO);
return;
}
if ((fds[0].revents & POLLERR) == POLLERR) {
LOG_ERR("Socket error: POLLERR");
LOG_ERR("Cloud connection was unexpectedly closed.");
error_handler(ERROR_CLOUD, -EIO);
return;
}
}
2. I queryed that the close socket-related function does not return the relevant event in the poll, and the shutdown function can return to the event detected by the poll, whether there is a function related to shutdown in nrf9160.