From d90b3c3779d9c6bd2884540621d107e4ac10e930 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 04 八月 2022 09:10:58 +0800
Subject: [PATCH] tcp remote reduce timeout in readrequest

---
 src/interface_bus_api.cpp |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/interface_bus_api.cpp b/src/interface_bus_api.cpp
index 638f31a..ccb75c8 100644
--- a/src/interface_bus_api.cpp
+++ b/src/interface_bus_api.cpp
@@ -341,11 +341,7 @@
     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;
-        url = "ipc:///tmp/" + procid;
-    }
+
     if (remote && remote_len > 0){
         BHAddress addr;
         if (addr.ParseFromArray(remote, remote_len)){
@@ -354,7 +350,12 @@
                 // printf("======>> BHRequest use remote address %s\n", url.c_str());
             }
         }
+    } else 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;
     }
+
     if (url.empty()) {
         set_last_error("bus_request url empty");
         return false;
@@ -383,13 +384,15 @@
     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;
+    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;
-        copy_memory(proc_id, proc_id_len, procid.data(), procid.size());
+    if (ret == REPLY_IPC){
+        string procid{};
+        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(request, request_len, msg.data(), msg.size());

--
Gitblit v1.8.0