From 4e5cb7960ce4e7e66d5190be67426aeca8b55c3d Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 09 四月 2021 18:45:08 +0800 Subject: [PATCH] add heartbeat, not tested yet. --- src/shm_queue.cpp | 31 ++++++++++++++----------------- 1 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/shm_queue.cpp b/src/shm_queue.cpp index dcb5a9e..652ed5b 100644 --- a/src/shm_queue.cpp +++ b/src/shm_queue.cpp @@ -60,15 +60,13 @@ } ShmMsgQueue::ShmMsgQueue(ShmType &segment, const int len) : - ShmMsgQueue(NewId(), segment, len) -{ -} + ShmMsgQueue(NewId(), segment, len) {} -ShmMsgQueue::~ShmMsgQueue() +ShmMsgQueue::~ShmMsgQueue() {} + +bool ShmMsgQueue::Remove(SharedMemory &shm, const MQId &id) { - // It's not safe to remove, others may still holder pointers and write to it. - // TODO use smart_ptr or garbage collection. - //Remove(); + return Super::Remove(shm, MsgQIdToName(id)); } bool ShmMsgQueue::Send(SharedMemory &shm, const MQId &remote_id, const MsgI &msg, const int timeout_ms, OnSend const &onsend) @@ -87,15 +85,14 @@ // 2) find remote queue first, then build msg; // 1 is about 50% faster than 2, maybe cache related. -bool ShmMsgQueue::Recv(BHMsg &msg, const int timeout_ms) -{ - MsgI imsg; - if (Read(imsg, timeout_ms)) { - DEFER1(imsg.Release(shm());); - return imsg.Unpack(msg); - } else { - return false; - } -} +// bool ShmMsgQueue::Recv(MsgI &imsg, BHMsgHead &head, const int timeout_ms) +// { +// if (Read(imsg, timeout_ms)) { +// // DEFER1(imsg.Release(shm());); +// return imsg.ParseHead(head); +// } else { +// return false; +// } +// } } // namespace bhome_shm -- Gitblit v1.8.0