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 <mike@foundries.io>
This commit is contained in:
Michael Scott 2019-02-12 17:10:41 -08:00 committed by Kumar Gala
commit 2ab50cb676

View file

@ -1024,8 +1024,6 @@ cleanup:
int lwm2m_send_message(struct lwm2m_message *msg) int lwm2m_send_message(struct lwm2m_message *msg)
{ {
int ret;
if (!msg || !msg->ctx) { if (!msg || !msg->ctx) {
LOG_ERR("LwM2M message is invalid."); LOG_ERR("LwM2M message is invalid.");
return -EINVAL; return -EINVAL;
@ -1037,13 +1035,12 @@ int lwm2m_send_message(struct lwm2m_message *msg)
msg->send_attempts++; msg->send_attempts++;
ret = send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); if (send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0) < 0) {
if (ret < 0) {
if (msg->type == COAP_TYPE_CON) { if (msg->type == COAP_TYPE_CON) {
coap_pending_clear(msg->pending); coap_pending_clear(msg->pending);
} }
return ret; return -errno;
} }
if (msg->type == COAP_TYPE_CON) { if (msg->type == COAP_TYPE_CON) {
@ -1058,7 +1055,7 @@ int lwm2m_send_message(struct lwm2m_message *msg)
lwm2m_reset_message(msg, true); lwm2m_reset_message(msg, true);
} }
return ret; return 0;
} }
u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size) 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_ctx *client_ctx;
struct lwm2m_message *msg; struct lwm2m_message *msg;
struct coap_pending *pending; struct coap_pending *pending;
int r;
client_ctx = CONTAINER_OF(work, struct lwm2m_ctx, retransmit_work); client_ctx = CONTAINER_OF(work, struct lwm2m_ctx, retransmit_work);
pending = coap_pending_next_to_expire(client_ctx->pendings, 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); LOG_DBG("Resending message: %p", msg);
msg->send_attempts++; msg->send_attempts++;
r = send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); if (send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0) < 0) {
if (r < 0) { LOG_ERR("Error sending lwm2m message: %d", -errno);
LOG_ERR("Error sending lwm2m message: %d", r);
/* don't error here, retry until timeout */ /* don't error here, retry until timeout */
} }