From 22cd4140502e67d32967160bee56375eaa285011 Mon Sep 17 00:00:00 2001
From: fujuntang <fujuntang@smartai.com>
Date: 星期二, 07 十二月 2021 16:18:34 +0800
Subject: [PATCH] Fix the service query fail issue.

---
 src/net/net_mod_socket_wrapper.cpp |    5 +++++
 src/net/net_mod_socket_wrapper.h   |    3 ++-
 src/net/net_mod_socket.h           |    3 ++-
 src/bh_api.cpp                     |   24 +++++++++++++++++-------
 src/net/net_mod_socket.cpp         |    4 ++++
 5 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/src/bh_api.cpp b/src/bh_api.cpp
index b768e7e..c450bc2 100644
--- a/src/bh_api.cpp
+++ b/src/bh_api.cpp
@@ -1244,7 +1244,8 @@
   char data_buf[MAX_STR_LEN] = { 0x00 };
   char buf_temp[MAX_STR_LEN] = { 0x00 };
   char *topics_buf = NULL;
-  
+  hashtable_t *hashtable = mm_get_hashtable();
+
 #if defined(PRO_DE_SERIALIZE)
   struct _BHAddress
 	{
@@ -1301,14 +1302,19 @@
 #else 
   strncpy(buf_temp, (char *)request, (sizeof(buf_temp) - 1) > strlen((char *)request) ? strlen((char *)request) : (sizeof(buf_temp) - 1));
 #endif 
- 
+
   str = buf_temp;
   val = net_mod_socket_buf_data_get(gNetmod_socket, str);
-  if(val > 0) {
-    
+  if ((val > 0) && (hashtable_get(hashtable, val) != NULL)) {
+
     rv = 0;
 
   } else {
+
+    if ((val > 0) && (hashtable_get(hashtable, val) == NULL)) {
+      net_mod_socket_buf_data_del(gNetmod_socket, str); 
+    }
+
     rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
     if (rv == 0) {
 
@@ -1420,7 +1426,8 @@
   char *errString = NULL;
   char buf_temp[MAX_STR_LEN] = { 0x00 };
   char *topics_buf = NULL;
-  
+  hashtable_t *hashtable = mm_get_hashtable();
+
   struct _RequestReply
   {
     std::string proc_id;
@@ -1487,10 +1494,13 @@
  
   str = buf_temp;
   val = net_mod_socket_buf_data_get(gNetmod_socket, str);
-  if(val > 0) {
+  if ((val > 0) && (hashtable_get(hashtable, val) != NULL)) {
     rv = 0;
-
   } else {
+    if ((val > 0) && (hashtable_get(hashtable, val) == NULL)) {
+      net_mod_socket_buf_data_del(gNetmod_socket, str);
+    }
+
     rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
     if (rv == 0) {
     
diff --git a/src/net/net_mod_socket.cpp b/src/net/net_mod_socket.cpp
index acd9053..d10fbdc 100644
--- a/src/net/net_mod_socket.cpp
+++ b/src/net/net_mod_socket.cpp
@@ -360,6 +360,10 @@
   return val;
 }
 
+void NetModSocket::buf_data_del(std::string str) {
+  recvbuf.erase(str); 
+}
+
 void NetModSocket::free_recv_msg_arr(net_mod_recv_msg_t * arr, size_t size) {
 
   for(int i =0; i< size; i++) {
diff --git a/src/net/net_mod_socket.h b/src/net/net_mod_socket.h
index bef1783..a7619f5 100644
--- a/src/net/net_mod_socket.h
+++ b/src/net/net_mod_socket.h
@@ -250,6 +250,7 @@
  
   void buf_data_set(std::string str, int val);
   int buf_data_get(std::string str);
+  void buf_data_del(std::string str);
 };
  
-#endif
\ No newline at end of file
+#endif
diff --git a/src/net/net_mod_socket_wrapper.cpp b/src/net/net_mod_socket_wrapper.cpp
index 038e8cf..8203a0a 100644
--- a/src/net/net_mod_socket_wrapper.cpp
+++ b/src/net/net_mod_socket_wrapper.cpp
@@ -133,6 +133,11 @@
   return sockt->buf_data_get(str);
 }
 
+void net_mod_socket_buf_data_del(void * _socket, std::string str) {
+  NetModSocket *sockt = (NetModSocket *)_socket;
+  sockt->buf_data_del(str);
+}
+
 /**
  * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅绛夊緟timeout鐨勬椂闂村悗杩斿洖
  * @timeout 绛夊緟鏃堕棿锛屽崟浣嶆槸鍗冨垎涔嬩竴绉�
diff --git a/src/net/net_mod_socket_wrapper.h b/src/net/net_mod_socket_wrapper.h
index c9ac313..c693b2f 100644
--- a/src/net/net_mod_socket_wrapper.h
+++ b/src/net/net_mod_socket_wrapper.h
@@ -134,6 +134,7 @@
 int net_mod_socket_svr_get(void * _socket);
 void net_mod_socket_buf_data_set(void * _socket, std::string str, int val);
 int net_mod_socket_buf_data_get(void * _socket, std::string str);
+void net_mod_socket_buf_data_del(void * _socket, std::string str);
 
 /**
  * @brief 璺ㄦ満鍣ㄥ彂閫佹秷鎭苟鎺ュ彈杩斿洖鐨勫簲绛旀秷鎭紝鐩村埌鍙戦�佸畬鎴愭墠杩斿洖
@@ -403,4 +404,4 @@
 }
 #endif
 
-#endif
\ No newline at end of file
+#endif

--
Gitblit v1.8.0