From db322f33ba13592f2492317e3f1a070454c97059 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期四, 13 五月 2021 19:34:46 +0800
Subject: [PATCH] center alloc all msgs.

---
 src/sendq.cpp |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/sendq.cpp b/src/sendq.cpp
index 5b57d72..36af264 100644
--- a/src/sendq.cpp
+++ b/src/sendq.cpp
@@ -16,10 +16,12 @@
  * =====================================================================================
  */
 #include "sendq.h"
-#include "shm_queue.h"
+#include "shm_msg_queue.h"
 #include <chrono>
 
-int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote remote, Array &arr)
+using namespace bhome_shm;
+
+int SendQ::DoSend1Remote(ShmMsgQueue &mq, const Remote remote, Array &arr)
 {
 	auto FirstNotExpired = [](Array &l) {
 		auto Less = [](const TimedMsg &msg, const TimePoint &tp) { return msg.expire() < tp; };
@@ -38,20 +40,24 @@
 	}
 
 	auto SendData = [&](Data &d) {
+		auto TryLoop = [&](auto &&data) {
+			for (int i = 0; i < 1; ++i) {
+				if (mq.TrySend(remote, data)) {
+					return true;
+				}
+			}
+			return false;
+		};
 		bool r = false;
 		if (d.index() == 0) {
 			auto &msg = boost::variant2::get<0>(pos->data().data_);
-			r = mq.TrySend(remote, msg);
+			r = TryLoop(msg);
 			if (r) {
 				msg.Release();
 			}
 		} else {
-			auto &content = boost::variant2::get<1>(pos->data().data_);
-			MsgI msg;
-			if (msg.Make(content)) {
-				DEFER1(msg.Release(););
-				r = mq.TrySend(remote, msg);
-			}
+			auto command = boost::variant2::get<1>(pos->data().data_);
+			r = TryLoop(command);
 		}
 		return r;
 	};
@@ -65,7 +71,7 @@
 	return nprocessed;
 }
 
-int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote remote, ArrayList &al)
+int SendQ::DoSend1Remote(ShmMsgQueue &mq, const Remote remote, ArrayList &al)
 {
 	int nsend = 0;
 	auto AllSent = [&](Array &arr) {
@@ -76,7 +82,7 @@
 	return nsend;
 }
 
-bool SendQ::TrySend(bhome_shm::ShmMsgQueue &mq)
+bool SendQ::TrySend(ShmMsgQueue &mq)
 {
 	std::unique_lock<std::mutex> lock(mutex_out_);
 	size_t nsend = 0;
@@ -108,4 +114,4 @@
 	Collect();
 
 	return !out_.empty();
-}
\ No newline at end of file
+}

--
Gitblit v1.8.0