From 9900e1211bc905eba5f333d699d74f28ceb94aed Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期一, 17 一月 2022 14:00:52 +0800
Subject: [PATCH] performance
---
src/nng_wrap.cpp | 3 ++-
src/interface_bus_api.cpp | 23 ++++++++++++-----------
src/bn_api.cpp | 20 ++++++++------------
3 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/src/bn_api.cpp b/src/bn_api.cpp
index 90e74ca..07773df 100644
--- a/src/bn_api.cpp
+++ b/src/bn_api.cpp
@@ -319,26 +319,23 @@
{
if (!request || request_len <= 0) return false;
+ string url{};
// BHQueryTopicAddress鑾峰彇proc_id
string procid{};
- if (!get_proc_id_from_MsgRequestTopic(request, request_len, timeout_ms, &procid)){
- 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());
}
}
}
- // 浣跨敤procid浣滀负ipc閫氫俊
- // printf("BHRequest procid %s\n", procid.c_str());
-
int rc = request2(url, request, request_len, reply, reply_len, timeout_ms);
if (rc < 0) return false;
@@ -360,11 +357,10 @@
if (ret != 0) return false;
string procid{};
- if (!get_proc_id_from_MsgRequestTopic(msg.data(), msg.size(), timeout_ms, &procid)){
- return false;
+ if (get_proc_id_from_MsgRequestTopic(msg.data(), msg.size(), timeout_ms, &procid)){
+ 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;
diff --git a/src/interface_bus_api.cpp b/src/interface_bus_api.cpp
index 60c195d..b005bdf 100644
--- a/src/interface_bus_api.cpp
+++ b/src/interface_bus_api.cpp
@@ -259,6 +259,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 +320,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 +361,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;
diff --git a/src/nng_wrap.cpp b/src/nng_wrap.cpp
index 6e23319..be364ee 100644
--- a/src/nng_wrap.cpp
+++ b/src/nng_wrap.cpp
@@ -162,6 +162,7 @@
}
int publish(const std::string& topic, const void* data, const int data_len, void* arg/*=NULL*/){
+ // printf("======>> publish topic %s\n", topic.c_str());
_ps* pub = (_ps*)arg;
if (!pub) pub = singleton<_ps>();
@@ -565,7 +566,7 @@
return !rep->msg_.empty();
});
if (!status){
- PRNTVITAG("subscribe_read timeout");
+ PRNTVITAG("read_request timeout");
return -1;
}
auto iter = rep->msg_.begin();
--
Gitblit v1.8.0