From 3c2b6739208d961cf8b86460d7f05516d044960c Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期三, 31 三月 2021 19:13:42 +0800 Subject: [PATCH] add async recv suport; sync by waiting for async. --- src/shm_queue.h | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/shm_queue.h b/src/shm_queue.h index f1e67f3..e9b3a1a 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,8 +133,20 @@ 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); + 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) + { + return Send(shm, remote_id, msg, timeout_ms, []() {}); + } + 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) + { + 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); -- Gitblit v1.8.0