From bef24e7b4001c7c7cd7a03a22f8eaf7c8af3c4b7 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 20 一月 2022 14:08:35 +0800
Subject: [PATCH] performance

---
 src/interface_bus_api.cpp |   44 ++++++++++++++++++++++++++------------------
 1 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/interface_bus_api.cpp b/src/interface_bus_api.cpp
index 60c195d..f2e7cfe 100644
--- a/src/interface_bus_api.cpp
+++ b/src/interface_bus_api.cpp
@@ -180,12 +180,12 @@
     return simple_request(url, query, query_len, reply, reply_len, timeout_ms);
 }
 
-int bus_subscribe_topics(void* handle, const void *topics,
+static int sub(const string& url,void* handle, const void *topics,
                       const int topics_len,
                       void **reply,
                       int *reply_len,
-                      const int timeout_ms)
-{
+                      const int timeout_ms){
+
     TAG;
     bus* b = get(handle);
     if (!b){
@@ -211,10 +211,8 @@
         subscribe_topic(mtl.topic_list(i), &get<2>(*b));
     }
 
-    return true;
-
 ///////////////////////////////////////////////////
-    auto ret = simple_request(get_url(URLSubLocal), topics, topics_len, reply, reply_len, timeout_ms);
+    auto ret = simple_request(url, topics, topics_len, reply, reply_len, timeout_ms);
     if (!ret){
         printf("bus_subscribe_topics simple_request failed\n");
     }
@@ -222,13 +220,22 @@
 
 }
 
+
+int bus_subscribe_topics(void* handle, const void *topics,
+                      const int topics_len,
+                      void **reply,
+                      int *reply_len,
+                      const int timeout_ms)
+{
+    return sub(get_url(URLSubLocal), handle, topics, topics_len, reply, reply_len, timeout_ms);
+}
 int bus_subscribe_topics_net(void* handle, const void *topics,
                          const int topics_len,
                          void **reply,
                          int *reply_len,
                          const int timeout_ms)
 {
-    return bus_subscribe_topics(handle, topics, topics_len, reply, reply_len, timeout_ms);
+    return sub(get_url(URLSubNet), handle, topics, topics_len, reply, reply_len, timeout_ms);
 }
 
 int bus_heartbeat_easy(void* handle, const int timeout_ms){ return 1; }
@@ -259,6 +266,7 @@
         return false;
     }
 
+    // msgpublish(msgpublish(msg))
     MsgPublish newPub;
     newPub.set_topic(get<8>(*b));
     newPub.set_data(string{(const char*)msgpub, (const size_t)msgpub_len});
@@ -319,20 +327,19 @@
         return false;
     }
 
+    string url{};
     // BHQueryTopicAddress鑾峰彇proc_id
     string procid{};
-    if (!get_proc_id_from_MsgRequestTopic(request, request_len, timeout_ms, &procid)){
-        PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
-        return false;
+    if (get_proc_id_from_MsgRequestTopic(request, request_len, timeout_ms, &procid)){
+        // PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
+        // return false;
+        url = "ipc:///tmp/" + procid;
     }
-
-    auto url("ipc:///tmp/" + procid);
-
     if (remote && remote_len > 0){
         BHAddress addr;
         if (addr.ParseFromArray(remote, remote_len)){
             if (!addr.ip().empty() && addr.port() > 0){
-                // url = "tcp://" + addr.ip() + ":" + to_string(addr.port());
+                url = "tcp://" + addr.ip() + ":" + to_string(addr.port());
                 printf("======>> BHRequest use remote address %s\n", url.c_str());
             }
         }
@@ -361,15 +368,16 @@
 
     string msg;
     auto ret = read_request(src, &msg, timeout_ms, &get<6>(*b));
+    // printf("bus_recv_request read_request ret %d msg %s\n", ret, msg.c_str());
     if (ret != 0) return false;
 
     string procid{};
-    if (!get_proc_id_from_MsgRequestTopic(msg.data(), msg.size(), timeout_ms, &procid)){
-        PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
-        return false;
+    if (get_proc_id_from_MsgRequestTopic(msg.data(), msg.size(), timeout_ms, &procid)){
+        // PRNTVITAG("get_proc_id_from_MsgRequestTopic failed");
+        // return false;
+        copy_memory(proc_id, proc_id_len, procid.data(), procid.size());
     }
 
-    copy_memory(proc_id, proc_id_len, procid.data(), procid.size());
     copy_memory(request, request_len, msg.data(), msg.size());
 
     return true;

--
Gitblit v1.8.0