From 1111184b74bb5b612c6f1838796b32afd556ba2b Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Tue, 27 Dec 2022 12:37:02 +0200 Subject: [PATCH] net: lwm2m: Remove lwm2m_send_message() from public API lwm2m_send_message() sends a message directly to the socket. Remove the function from public API and combine the code with socket_send_message(). Signed-off-by: Juha Ylinen --- subsys/net/lib/lwm2m/lwm2m_engine.c | 28 ++++++++++++++++- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 30 ------------------- subsys/net/lib/lwm2m/lwm2m_message_handling.h | 1 - 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 8b2984ef1de..1f18da7234d 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -633,14 +633,40 @@ static int socket_recv_message(struct lwm2m_ctx *client_ctx) static int socket_send_message(struct lwm2m_ctx *client_ctx) { + int rc; sys_snode_t *msg_node = sys_slist_get(&client_ctx->pending_sends); struct lwm2m_message *msg; if (!msg_node) { return 0; } + msg = SYS_SLIST_CONTAINER(msg_node, msg, node); - return lwm2m_send_message(msg); + if (!msg || !msg->ctx) { + LOG_ERR("LwM2M message is invalid."); + return -EINVAL; + } + + if (msg->type == COAP_TYPE_CON) { + coap_pending_cycle(msg->pending); + } + + rc = zsock_send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); + + 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; + } + + if (msg->type != COAP_TYPE_CON) { + lwm2m_reset_message(msg, true); + } + + return 0; } static void socket_reset_pollfd_events(void) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 7597c3e94c5..a9a8952b09f 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -441,36 +441,6 @@ int lwm2m_information_interface_send(struct lwm2m_message *msg) return 0; } -int lwm2m_send_message(struct lwm2m_message *msg) -{ - int rc; - - if (!msg || !msg->ctx) { - LOG_ERR("LwM2M message is invalid."); - return -EINVAL; - } - - if (msg->type == COAP_TYPE_CON) { - coap_pending_cycle(msg->pending); - } - - rc = zsock_send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); - - 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; - } - - if (msg->type != COAP_TYPE_CON) { - lwm2m_reset_message(msg, true); - } - - return 0; -} int lwm2m_send_empty_ack(struct lwm2m_ctx *client_ctx, uint16_t mid) { struct lwm2m_message *msg; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index c94f7f3890b..ca8c89465cc 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -42,7 +42,6 @@ struct lwm2m_message *find_msg(struct coap_pending *pending, struct coap_reply * void lwm2m_reset_message(struct lwm2m_message *msg, bool release); void lm2m_message_clear_allocations(struct lwm2m_message *msg); int lwm2m_init_message(struct lwm2m_message *msg); -int lwm2m_send_message(struct lwm2m_message *msg); int lwm2m_send_message_async(struct lwm2m_message *msg); int handle_request(struct coap_packet *request, struct lwm2m_message *msg);