From c1e39e20ca42b21eeac8b5068fa1f921bf9a070f Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期三, 23 六月 2021 19:43:29 +0800
Subject: [PATCH] refactor, start tcp pub/sub.

---
 box/tcp_connection.cpp |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/box/tcp_connection.cpp b/box/tcp_connection.cpp
index 85ed4ed..6506369 100644
--- a/box/tcp_connection.cpp
+++ b/box/tcp_connection.cpp
@@ -178,8 +178,17 @@
 			send_buffer_ = imsg.content();
 			async_write(socket_, Buffer(send_buffer_), TcpCBSize(*this, [this]() { Close(); }));
 		};
+
 		auto &scenter = *pscenter_;
-		if (scenter->PassRemoteRequestToLocal(remote, head, body_content, onRecv)) {
+		if (head.type() == kMsgTypePublish) {
+			auto reply = MakeReply(eSuccess);
+			auto rep_head = InitMsgHead(GetType(reply), scenter->id(), 0, head.msg_id());
+			send_buffer_ = MsgI::Serialize(rep_head, reply);
+			async_write(socket_, Buffer(send_buffer_), TcpCBSize(*this, [this]() { Close(); }));
+
+			scenter->RemotePublish(head, body_content);
+			return;
+		} else if (scenter->PassRemoteRequestToLocal(remote, head, body_content, onRecv)) {
 			return;
 		} else {
 			Close();

--
Gitblit v1.8.0