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.h | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/shm_queue.h b/src/shm_queue.h index 9064f55..20ff3dc 100644 --- a/src/shm_queue.h +++ b/src/shm_queue.h @@ -118,6 +118,7 @@ { typedef ShmObject<SharedQueue<MsgI>> Super; typedef Super::Data Queue; + typedef std::function<void()> OnSend; bool Write(const MsgI &buf, const int timeout_ms) { return data()->Write(buf, timeout_ms); } bool Read(MsgI &buf, const int timeout_ms) { return data()->Read(buf, timeout_ms); } MQId id_; @@ -128,16 +129,17 @@ ShmMsgQueue(const MQId &id, ShmType &segment, const int len); ShmMsgQueue(ShmType &segment, const int len); ~ShmMsgQueue(); + static bool Remove(SharedMemory &shm, const MQId &id); const MQId &Id() const { return id_; } - bool Recv(BHMsg &msg, const int timeout_ms); + // bool Recv(MsgI &msg, BHMsgHead &head, const int timeout_ms); bool Recv(MsgI &msg, const int timeout_ms) { return Read(msg, timeout_ms); } - bool Send(const MQId &remote_id, const BHMsg &msg, const int timeout_ms); + static bool Send(SharedMemory &shm, const MQId &remote_id, const MsgI &msg, const int timeout_ms, OnSend const &onsend); static bool Send(SharedMemory &shm, const MQId &remote_id, const MsgI &msg, const int timeout_ms); - bool Send(const MQId &remote_id, const MsgI &msg, const int timeout_ms) - { - return Send(shm(), remote_id, msg, timeout_ms); - } + + template <class... Rest> + bool Send(const MQId &remote_id, Rest const &...rest) { return Send(shm(), remote_id, rest...); } + size_t Pending() const { return data()->size(); } }; } // namespace bhome_shm -- Gitblit v1.8.0