From 2ab50cb6769907d99252b83d46a5d36bc2deb65a Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Tue, 12 Feb 2019 17:10:41 -0800 Subject: [PATCH] net: lwm2m: Follow POSIX send() API send() returns -1 upon error and sets errno appropriately. Let's not bother saving the return code and instead share errno back to the user. Signed-off-by: Michael Scott --- subsys/net/lib/lwm2m/lwm2m_engine.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 77d70d6c975..b4ccccb5d09 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -1024,8 +1024,6 @@ cleanup: int lwm2m_send_message(struct lwm2m_message *msg) { - int ret; - if (!msg || !msg->ctx) { LOG_ERR("LwM2M message is invalid."); return -EINVAL; @@ -1037,13 +1035,12 @@ int lwm2m_send_message(struct lwm2m_message *msg) msg->send_attempts++; - ret = send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); - if (ret < 0) { + if (send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0) < 0) { if (msg->type == COAP_TYPE_CON) { coap_pending_clear(msg->pending); } - return ret; + return -errno; } if (msg->type == COAP_TYPE_CON) { @@ -1058,7 +1055,7 @@ int lwm2m_send_message(struct lwm2m_message *msg) lwm2m_reset_message(msg, true); } - return ret; + return 0; } u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size) @@ -3560,7 +3557,6 @@ static void retransmit_request(struct k_work *work) struct lwm2m_ctx *client_ctx; struct lwm2m_message *msg; struct coap_pending *pending; - int r; client_ctx = CONTAINER_OF(work, struct lwm2m_ctx, retransmit_work); pending = coap_pending_next_to_expire(client_ctx->pendings, @@ -3591,9 +3587,8 @@ static void retransmit_request(struct k_work *work) LOG_DBG("Resending message: %p", msg); msg->send_attempts++; - r = send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); - if (r < 0) { - LOG_ERR("Error sending lwm2m message: %d", r); + if (send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0) < 0) { + LOG_ERR("Error sending lwm2m message: %d", -errno); /* don't error here, retry until timeout */ }