net: lwm2m: Don't ignore socket errors when sending

Only socket error that we should ignore is EAGAIN (EWOULDBLOCK),
others might be indicating that there are some serious errors
in network layer.
When network stack would block us, just drop the packet and
let CoAP layer handle the retrying.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
This commit is contained in:
Seppo Takalo 2023-02-21 14:19:46 +02:00 committed by Carles Cufí
parent ea1eb28135
commit 96a4bedd30

View File

@ -662,18 +662,14 @@ static int socket_send_message(struct lwm2m_ctx *client_ctx)
if (rc < 0) {
LOG_ERR("Failed to send packet, err %d", errno);
if (msg->type != COAP_TYPE_CON) {
lwm2m_reset_message(msg, true);
}
return -errno;
rc = -errno;
}
if (msg->type != COAP_TYPE_CON) {
lwm2m_reset_message(msg, true);
}
return 0;
return rc;
}
static void socket_reset_pollfd_events(void)
@ -782,7 +778,15 @@ static void socket_loop(void)
}
if (sock_fds[i].revents & ZSOCK_POLLOUT) {
socket_send_message(sock_ctx[i]);
rc = socket_send_message(sock_ctx[i]);
/* Drop packets that cannot be send, CoAP layer handles retry */
/* Other fatal errors should trigger a recovery */
if (rc < 0 && rc != -EAGAIN) {
LOG_ERR("send() reported a socket error, %d", -rc);
if (sock_ctx[i] != NULL && sock_ctx[i]->fault_cb != NULL) {
sock_ctx[i]->fault_cb(-rc);
}
}
}
}
}