From 68c7bef33e74f23aa0136ccd6f7faa654d671ebc Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 21 五月 2021 09:23:01 +0800 Subject: [PATCH] center publish notify; fix topic partial match. --- src/msg.cpp | 45 +++++++++++++++++++++++++++++++++++---------- 1 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/msg.cpp b/src/msg.cpp index e8c6d26..dca2044 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -16,20 +16,45 @@ * ===================================================================================== */ #include "msg.h" +#include "bh_util.h" +#include "defs.h" +#include "shm_socket.h" -namespace bhome_shm { - - -bool MsgMetaV1::Parse(const void *p) +namespace bhome_msg { - assert(p); - *this = *static_cast<const MsgMetaV1*>(p); - return tag_ == kMsgMetaTag; + +ShmSocket &ShmMsg::Sender() +{ + static auto &mq = GetCenterInfo(shm())->mq_sender_; + static ShmSocket sender(mq.offset_, shm(), mq.id_); + return sender; } -void MsgMetaV1::Pack(void *p) +int ShmMsg::Release() { - *static_cast<MsgMetaV1*>(p) = *this; + if (!valid()) { + return 0; + } + auto n = meta()->count_.Dec(); + if (n == 0) { + if (meta()->managed_) { + int64_t free_cmd = (id() << 4) | EncodeCmd(eCmdFree); + Sender().Send(BHTopicCenterAddress(), free_cmd); + } else { + Free(); + } + } else if (n < 0) { + LOG_FATAL() << "error double release data."; + throw std::runtime_error("double release msg."); + } + return n; } -} // namespace bhome_shm +void ShmMsg::Free() +{ + assert(valid()); + shm().Dealloc(meta()); + offset_ = 0; + assert(!valid()); +} +} // namespace bhome_msg -- Gitblit v1.8.0