From dc12826dd61ce18fac3a9561c5843d30a0cf9660 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期五, 02 四月 2021 15:48:53 +0800 Subject: [PATCH] add request topic cache; refactor req/rep center. --- src/reqrep.cpp | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/reqrep.cpp b/src/reqrep.cpp index bed6496..79ff892 100644 --- a/src/reqrep.cpp +++ b/src/reqrep.cpp @@ -155,8 +155,7 @@ bool SocketRequest::QueryRPCTopic(const std::string &topic, bhome::msg::BHAddress &addr, const int timeout_ms) { - if (tmp_cache_.first == topic) { - addr = tmp_cache_.second; + if (topic_cache_.Find(topic, addr)) { return true; } @@ -167,9 +166,12 @@ DataProcQueryTopicReply reply; if (reply.ParseFromString(result.body())) { addr = reply.address(); - tmp_cache_.first = topic; - tmp_cache_.second = addr; - return !addr.mq_id().empty(); + if (addr.mq_id().empty()) { + return false; + } else { + topic_cache_.Update(topic, addr); + return true; + } } } } else { -- Gitblit v1.8.0