From bb9a7e348892eb5c4fccb063380aa6fcd9612b71 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 06 四月 2021 17:32:35 +0800 Subject: [PATCH] server resend failed; rename msgs; refactor. --- src/shm_queue.h | 30 +++++++++++++++++------------- 1 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/shm_queue.h b/src/shm_queue.h index e9b3a1a..ab8a88c 100644 --- a/src/shm_queue.h +++ b/src/shm_queue.h @@ -134,22 +134,26 @@ bool Recv(BHMsg &msg, const int timeout_ms); bool Recv(MsgI &msg, const int timeout_ms) { return Read(msg, 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) + static bool Send(SharedMemory &shm, 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...); } - bool Send(const MQId &remote_id, const BHMsg &msg, const int timeout_ms, OnSend const &onsend); - bool Send(const MQId &remote_id, const BHMsg &msg, const int timeout_ms) + + template <class... Extra> + bool Send(const MQId &remote_id, const BHMsg &data, const int timeout_ms, Extra const &...extra) { - return Send(remote_id, msg, timeout_ms, []() {}); - } - bool Send(const MQId &remote_id, const MsgI &msg, const int timeout_ms, OnSend const &onsend) - { - return Send(shm(), remote_id, msg, timeout_ms, onsend); - } - bool Send(const MQId &remote_id, const MsgI &msg, const int timeout_ms) - { - return Send(shm(), remote_id, msg, timeout_ms); + 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(); } }; -- Gitblit v1.8.0