From fa95ddd1a294ebad47cabf9e149ee7d789271044 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期三, 14 四月 2021 19:45:09 +0800
Subject: [PATCH] use 2 buf to speed up sendq; socket auto start.

---
 src/sendq.h |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/sendq.h b/src/sendq.h
index c6f270b..92e566b 100644
--- a/src/sendq.h
+++ b/src/sendq.h
@@ -23,6 +23,7 @@
 #include "timed_queue.h"
 #include <deque>
 #include <functional>
+#include <mutex>
 #include <string>
 #include <unordered_map>
 
@@ -62,13 +63,29 @@
 	static TimePoint Now() { return TimedMsg::Clock::now(); }
 	void Append(const Remote &addr, const MsgI &msg, const TimePoint &expire, OnMsgEvent onExpire)
 	{
+		//TODO simple queue, organize later ?
+
 		msg.AddRef();
-		store_[addr].emplace_back(TimedMsg(expire, MsgInfo{msg, onExpire}));
+		TimedMsg tmp(expire, MsgInfo{msg, onExpire});
+		std::unique_lock<std::mutex> lock(mutex_);
+		in_[addr].emplace_back(std::move(tmp));
 	}
 	typedef std::deque<TimedMsg> MsgList;
 	typedef std::unordered_map<Remote, MsgList> Store;
+	class MsgIter
+	{
+		MsgList::iterator iter_;
 
-	Store store_;
+	public:
+		MsgIter(MsgList::iterator iter) :
+		    iter_(iter) {}
+		MsgIter &operator++() { return ++iter_, *this; }
+		bool operator==(const MsgIter &a) { return iter_ == a.iter_; }
+		MsgI &operator*() { return iter_->data().msg_; }
+	};
+	std::mutex mutex_;
+	Store in_;
+	Store out_;
 };
 
 #endif // end of include guard: SENDQ_IWKMSK7M

--
Gitblit v1.8.0