From 82b028cf63953d8080b63d85468eae488d212194 Mon Sep 17 00:00:00 2001
From: fujuntang <fujuntang@smartai.com>
Date: 星期四, 23 九月 2021 14:30:07 +0800
Subject: [PATCH] Fix the data parsing when in multiple threads.

---
 src/bh_api.cpp |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/bh_api.cpp b/src/bh_api.cpp
index 312b203..32e53ef 100644
--- a/src/bh_api.cpp
+++ b/src/bh_api.cpp
@@ -530,9 +530,10 @@
     if (mtr_list_num > sizeof(mtr_list) / sizeof(mtr_list[0])) {
       mtr_list_num = sizeof(mtr_list) / sizeof(mtr_list[0]);
     }
-    
+  
+    Proc_ptr = &(ptr->procData);
     for(int i = 0; i < mtr_list_num; i++) {
-      mtr_list[i].proc_id = ptr->procData.proc_id;
+      mtr_list[i].proc_id = (Proc_ptr + i)->proc_id;
       mtr_list[i].mq_id = ID_RSV;
       mtr_list[i].abs_addr = ABS_ID_RSV;
       mtr_list[i].ip = "127.0.0.1";
@@ -1162,6 +1163,7 @@
   int sec, nsec;
   std::string MsgID;
   int timeout_ms = 3000;
+  char data_buf[MAX_STR_LEN] = { 0x00 };
   char buf_temp[MAX_STR_LEN] = { 0x00 };
   char *topics_buf = NULL;
   
@@ -1225,7 +1227,9 @@
   rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
   if (rv == 0) {
 
-    val = atoi((char *)buf);
+    len = size > (sizeof(data_buf) - 1) ? (sizeof(data_buf) - 1) : size;
+    memcpy(data_buf, (char *)buf, len);
+    val = atoi((char *)data_buf);
 
     free(buf);
 
@@ -1316,6 +1320,7 @@
   net_node_t node;
   int node_size;  
   int recv_arr_size;
+  char data_buf[MAX_STR_LEN] = { 0x00 };
   net_mod_recv_msg_t *recv_arr;
   net_mod_err_t *errarr;
   int errarr_size = 0;
@@ -1389,7 +1394,9 @@
   rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
   if (rv == 0) {
     
-    val = atoi((char *)buf);
+    len = size > (sizeof(data_buf) - 1) ? (sizeof(data_buf) - 1) : size;
+    memcpy(data_buf, (char *)buf, len);
+    val = atoi((char *)data_buf);
 
     free(buf);
 
@@ -1401,7 +1408,6 @@
       len += strlen(_input1.data);
 #endif
 
-      data = net_mod_socket_svr_get(gNetmod_socket);
       topics_buf = (char *)malloc(len);
       if (topics_buf == NULL) {
         

--
Gitblit v1.8.0