From 13c503b73b4ecc8ce4a6e344f9ac15202985d686 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 20 七月 2021 19:48:58 +0800 Subject: [PATCH] fix memory leak --- src/defs.h | 44 ++++++++++++++++++++++++++------------------ 1 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/defs.h b/src/defs.h index 5c770a7..ec41371 100644 --- a/src/defs.h +++ b/src/defs.h @@ -19,27 +19,26 @@ #ifndef DEFS_KP8LKGD0 #define DEFS_KP8LKGD0 +#include "robust.h" #include <atomic> #include <string> +class ShmSocket; typedef uint64_t MQId; int64_t CalcAllocIndex(int64_t size); int64_t GetAllocSize(int index); -struct CenterInfo { - struct MQInfo { - int64_t id_ = 0; - int64_t offset_ = 0; - }; +struct MQInfo { + MQId id_ = 0; + int64_t offset_ = 0; +}; +struct CenterInfo { MQInfo mq_center_; MQInfo mq_bus_; - MQInfo mq_init_; MQInfo mq_sender_; - std::atomic<MQId> mqid_; - CenterInfo() : - mqid_(100000) {} + robust::AtomicReqRep init_rr_; }; const int kBHCenterPort = 24287; @@ -49,19 +48,28 @@ class SharedMemory; } // namespace bhome_shm +using bhome_shm::SharedMemory; + std::string BHomeShmName(); -bhome_shm::SharedMemory &BHomeShm(); -CenterInfo *GetCenterInfo(bhome_shm::SharedMemory &shm); -bool CenterInit(bhome_shm::SharedMemory &shm); -bool GlobalInit(bhome_shm::SharedMemory &shm); +SharedMemory &BHomeShm(); +CenterInfo *GetCenterInfo(SharedMemory &shm); +ShmSocket &DefaultSender(SharedMemory &shm); + +MQId NewSession(); +bool CenterInit(); +bool GlobalInit(SharedMemory &shm); typedef std::string Topic; void SetLastError(const int ec, const std::string &msg); void GetLastError(int &ec, std::string &msg); -//TODO center can check shm for previous crash. -uint64_t BHGlobalSenderAddress(); -uint64_t BHTopicCenterAddress(); -uint64_t BHTopicBusAddress(); -uint64_t BHCenterReplyAddress(); +const MQInfo &BHTopicCenterAddress(SharedMemory &shm); +const MQInfo &BHTopicBusAddress(SharedMemory &shm); +bool BHNodeInit(SharedMemory &shm, const int64_t request, int64_t &reply); +void BHCenterHandleInit(SharedMemory &shm, std::function<int64_t(const int64_t)> const &onReq); + +// node mq is avail with in timeout; after that may get killed. +int NodeTimeoutSec(); + +std::string BHLogDir(); #endif // end of include guard: DEFS_KP8LKGD0 -- Gitblit v1.8.0