From c338820e4db43ad32c20ff429a038b06bcb980f8 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期四, 08 四月 2021 18:13:25 +0800
Subject: [PATCH] BIG change, join center,bus; now msg is head+body.

---
 src/shm_queue.h |   32 ++++++++++++++++++--------------
 1 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/shm_queue.h b/src/shm_queue.h
index e9b3a1a..32ccfae 100644
--- a/src/shm_queue.h
+++ b/src/shm_queue.h
@@ -131,26 +131,30 @@
 	~ShmMsgQueue();
 	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); }
 	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 Body, class... Extra>
+	bool Send(const MQId &remote_id, const BHMsgHead &head, const Body &body, const int timeout_ms, Extra const &...extra)
 	{
-		return Send(remote_id, msg, timeout_ms, []() {});
+		MsgI msg;
+		if (msg.Make(shm(), head, body)) {
+			if (Send(shm(), remote_id, msg, timeout_ms, extra...)) {
+				return true;
+			} else {
+				msg.Release(shm());
+			}
+		}
+		return false;
 	}
-	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);
-	}
+
 	size_t Pending() const { return data()->size(); }
 };
 

--
Gitblit v1.8.0