From 4deeafbd502dc3c57dab8ad6ca601a38a9e7f074 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 06 四月 2021 19:10:49 +0800 Subject: [PATCH] add uni center. --- src/shm_queue.h | 24 +++++++++++++++++++++--- 1 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/shm_queue.h b/src/shm_queue.h index 9064f55..ab8a88c 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_; @@ -132,12 +133,29 @@ bool Recv(BHMsg &msg, 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) + + template <class... Extra> + bool Send(const MQId &remote_id, const MsgI &msg, const int timeout_ms, Extra const &...extra) { - return Send(shm(), remote_id, msg, timeout_ms); + return Send(shm(), remote_id, msg, timeout_ms, extra...); } + + template <class... Extra> + bool Send(const MQId &remote_id, const BHMsg &data, const int timeout_ms, Extra const &...extra) + { + MsgI msg; + if (msg.Make(shm(), data)) { + if (Send(shm(), remote_id, msg, timeout_ms, extra...)) { + return true; + } else { + msg.Release(shm()); + } + } + return false; + } + size_t Pending() const { return data()->size(); } }; } // namespace bhome_shm -- Gitblit v1.8.0