From e98afa80d9ec2b3413d734f415060bb10220b698 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Fri, 6 Oct 2023 18:05:14 +0200 Subject: [PATCH] fixed another memory leak: handle received result responses just remove them from the queue. --- apps/aqhome-nodes/0BUILD | 2 + apps/aqhome-nodes/loop.c | 16 +++++++ apps/aqhome-nodes/loop_broker.c | 76 +++++++++++++++++++++++++++++++++ apps/aqhome-nodes/loop_broker.h | 23 ++++++++++ 4 files changed, 117 insertions(+) create mode 100644 apps/aqhome-nodes/loop_broker.c create mode 100644 apps/aqhome-nodes/loop_broker.h diff --git a/apps/aqhome-nodes/0BUILD b/apps/aqhome-nodes/0BUILD index d714c0c..c72ddf6 100644 --- a/apps/aqhome-nodes/0BUILD +++ b/apps/aqhome-nodes/0BUILD @@ -38,6 +38,7 @@ init.h fini.h loop.h + loop_broker.h loop_tty.h loop_tty_ipc.h loop_tty_broker.h @@ -53,6 +54,7 @@ init.c fini.c loop.c + loop_broker.c loop_tty.c loop_tty_ipc.c loop_tty_broker.c diff --git a/apps/aqhome-nodes/loop.c b/apps/aqhome-nodes/loop.c index 010aa18..21dc684 100644 --- a/apps/aqhome-nodes/loop.c +++ b/apps/aqhome-nodes/loop.c @@ -14,6 +14,7 @@ #include "./loop.h" #include "./loop_tty.h" #include "./loop_ipc.h" +#include "./loop_broker.h" #include "./aqhomed_p.h" #include "./tty_log.h" #include "./db.h" @@ -61,6 +62,21 @@ void AqHomed_Loop(AQHOMED *aqh, int timeoutInMsecs) GWEN_MsgEndpoint_ChildrenIoLoop(aqh->rootEndpoint, timeoutInMsecs); AqHomed_ReadAndHandleTtyMessages(aqh); AqHomed_ReadAndHandleIpcMessages(aqh); + AqHomed_ReadAndHandleBrokerMessages(aqh); + +#if 0 + DBG_ERROR(NULL, "Messages in TTY queue: %d in, %d out", + GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetReceivedMessageList(aqh->ttyEndpoint)), + GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetSendMessageList(aqh->ttyEndpoint))); + + DBG_ERROR(NULL, "Messages in IPC queue: %d in, %d out", + GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetReceivedMessageList(aqh->ipcdEndpoint)), + GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetSendMessageList(aqh->ipcdEndpoint))); + + DBG_ERROR(NULL, "Messages in Broker queue: %d in, %d out", + GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetReceivedMessageList(aqh->brokerEndpoint)), + GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetSendMessageList(aqh->brokerEndpoint))); +#endif if (AQH_NodeDb_IsModified(aqh->nodeDb)) { if (aqh->dbFile) { diff --git a/apps/aqhome-nodes/loop_broker.c b/apps/aqhome-nodes/loop_broker.c new file mode 100644 index 0000000..c01ac7c --- /dev/null +++ b/apps/aqhome-nodes/loop_broker.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + + +#include "./loop_broker.h" +#include "./aqhomed_p.h" +#include "./tty_log.h" +#include "./db.h" + +#include "aqhome/msg/endpoint_tty.h" +#include "aqhome/msg/msg_node.h" +#include "aqhome/msg/msg_value2.h" +#include "aqhome/msg/msg_ping.h" +#include "aqhome/ipc/endpoint_ipc.h" +#include "aqhome/ipc/msg_ipc_result.h" + +#include +#include +#include +#include + + + +/* ------------------------------------------------------------------------------------------------ + * defines + * ------------------------------------------------------------------------------------------------ + */ + + + +/* ------------------------------------------------------------------------------------------------ + * forward declarations + * ------------------------------------------------------------------------------------------------ + */ + + + +/* ------------------------------------------------------------------------------------------------ + * implementations + * ------------------------------------------------------------------------------------------------ + */ + + +void AqHomed_ReadAndHandleBrokerMessages(AQHOMED *aqh) +{ + if (aqh->brokerEndpoint) { + GWEN_MSG_ENDPOINT *epTcp; + GWEN_MSG *msg; + + epTcp=aqh->brokerEndpoint; + while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp)) ) { + uint16_t code; + + code=GWEN_IpcMsg_GetCode(msg); + DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC packet %d (%x)", (int) code, code); + + GWEN_Msg_free(msg); + } + } +} + + + + + + + diff --git a/apps/aqhome-nodes/loop_broker.h b/apps/aqhome-nodes/loop_broker.h new file mode 100644 index 0000000..2bbded7 --- /dev/null +++ b/apps/aqhome-nodes/loop_broker.h @@ -0,0 +1,23 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifndef AQHOMED_LOOP_BROKER_H +#define AQHOMED_LOOP_BROKER_H + + +#include "./aqhomed.h" + + + +void AqHomed_ReadAndHandleBrokerMessages(AQHOMED *aqh); + + + +#endif + +