Fu Juntang
2021-09-13 0cc00936da93b7003b882c58af01c1345f9cac38
src/bh_api.cpp
@@ -139,6 +139,12 @@
    gNetmod_socket = net_mod_socket_open();
    hashtable_t *hashtable = mm_get_hashtable();
    key = hashtable_alloc_key(hashtable);
    count = hashtable_alloc_key(hashtable);
    rv = hashtable_alloc_key(hashtable);
    net_mod_socket_int_set(gNetmod_socket, count);
    net_mod_socket_svr_set(gNetmod_socket, rv);
    sprintf(pData.int_info, "%d", count);
    sprintf(pData.svr_info, "%d", rv);
    net_mod_socket_bind(gNetmod_socket, key);
  
    rv = net_mod_socket_reg(gNetmod_socket, &pData, sizeof(ProcInfo), NULL, 0, timeout_ms, PROC_REG);
@@ -341,60 +347,46 @@
    return false;
  }
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
    topics_buf = (char *)malloc(total);
    if (topics_buf == NULL) {
      rv = EBUS_NO_MEM;
      memset(errString, 0x00, sizeof(errString));
      strncpy(errString, bus_strerror(rv), sizeof(errString));
      logger->error("in BHRegisterTopics: Out of memory!\n");
      pthread_mutex_unlock(&mutex);
      return false;
    }
    memset(topics_buf, 0x00, total);
#if defined(PRO_DE_SERIALIZE)
    for (i = 0; i < _input.amount; i++) {
      len = strlen(_input.topics[i]);
      strncpy(topics_buf + count, _input.topics[i], len);
      count += len;
      if ((_input.amount > 1) && (i < (_input.amount - 1))) {
        strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC));
        count++;
      }
    }
#else
    memcpy(topics_buf, topics, topics_len);
    count = topics_len;
#endif
    rv = net_mod_socket_reg(gNetmod_socket, topics_buf, count, NULL, 0, timeout_ms, PROC_REG_TCS);
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    free(topics_buf);
    pthread_mutex_unlock(&mutex);
  } else {
    rv = EBUS_RES_BUSY;
  topics_buf = (char *)malloc(total);
  if (topics_buf == NULL) {
    rv = EBUS_NO_MEM;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    
    logger->error("in BHRegisterTopics: Out of memory!\n");
    return false;
  }
  memset(topics_buf, 0x00, total);
#if defined(PRO_DE_SERIALIZE)
  for (i = 0; i < _input.amount; i++) {
    len = strlen(_input.topics[i]);
    strncpy(topics_buf + count, _input.topics[i], len);
    count += len;
    if ((_input.amount > 1) && (i < (_input.amount - 1))) {
      strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC));
      count++;
    }
  }
#else
  memcpy(topics_buf, topics, topics_len);
  count = topics_len;
#endif
  rv = net_mod_socket_reg(gNetmod_socket, topics_buf, count, NULL, 0, timeout_ms, PROC_REG_TCS);
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
  free(topics_buf);
#if defined(PRO_DE_SERIALIZE)
  ::bhome_msg::MsgCommonReply mcr;
   mcr.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv));
@@ -475,33 +467,19 @@
    return false;
  }
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
#if defined(PRO_DE_SERIALIZE)
    min = (strlen(_input1) > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : strlen(_input1));
    strncpy(topics_buf, _input1, min);
  min = (strlen(_input1) > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : strlen(_input1));
  strncpy(topics_buf, _input1, min);
#else 
    min = (topic_len > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : topic_len);
    buf = const_cast<void *>(topic);
    strncpy(topics_buf, (const char *)buf, min);
  min = (topic_len > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : topic_len);
  buf = const_cast<void *>(topic);
  strncpy(topics_buf, (const char *)buf, min);
#endif 
    rv = net_mod_socket_reg(gNetmod_socket, topics_buf, min, &buf, &size, timeout_ms, PROC_QUE_TCS);
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    pthread_mutex_unlock(&mutex);
  rv = net_mod_socket_reg(gNetmod_socket, topics_buf, min, &buf, &size, timeout_ms, PROC_QUE_TCS);
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
    
  } else {
    rv = EBUS_RES_BUSY;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    return false;
  }
#if defined(PRO_DE_SERIALIZE)
   struct _MsgQueryTopicReply
@@ -626,28 +604,14 @@
    return false;
  }
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
    if (query != NULL) {
      strncpy(data_buf, (char *)query, (sizeof(data_buf) - 1) > query_len ? query_len : (sizeof(data_buf) - 1));
    }
    rv = net_mod_socket_reg(gNetmod_socket, data_buf, strlen(data_buf), &buf, &size, timeout_ms, PROC_QUE_ATCS);
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    pthread_mutex_unlock(&mutex);
  } else {
    rv = EBUS_RES_BUSY;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    return false;
  if (query != NULL) {
    strncpy(data_buf, (char *)query, (sizeof(data_buf) - 1) > query_len ? query_len : (sizeof(data_buf) - 1));
  }
  rv = net_mod_socket_reg(gNetmod_socket, data_buf, strlen(data_buf), &buf, &size, timeout_ms, PROC_QUE_ATCS);
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
  
#if defined(PRO_DE_SERIALIZE)
  struct _MsgQueryProcReply
@@ -793,74 +757,59 @@
    return false;
  }
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
    topics_buf = (char *)malloc(total);
    if (topics_buf == NULL) {
      rv = EBUS_NO_MEM;
      memset(errString, 0x00, sizeof(errString));
      strncpy(errString, bus_strerror(rv), sizeof(errString));
      logger->error("in BHSubscribeTopics: Out of memory!\n");
  
      pthread_mutex_unlock(&mutex);
      return false;
    }
    memset(topics_buf, 0x00, total);
#if defined(PRO_DE_SERIALIZE)
    for (i = 0; i < _input.amount; i++) {
      len = strlen(_input.topics[i]);
      strncpy(topics_buf + count, _input.topics[i], len);
      count += len;
      if ((_input.amount > 1) && (i < (_input.amount - 1))) {
        strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC));
        count++;
      }
    }
#else
    memcpy(topics_buf, topics, topics_len);
    count = topics_len;
#endif
    if (timeout_ms > 0) {
  topics_buf = (char *)malloc(total);
  if (topics_buf == NULL) {
    
      sec = timeout_ms / 1000;
      nsec = (timeout_ms - sec * 1000) * 1000 * 1000;
      rv = net_mod_socket_sub_timeout(gNetmod_socket, topics_buf, count, sec, nsec);
    } else if (timeout_ms == 0) {
      rv = net_mod_socket_sub_nowait(gNetmod_socket, topics_buf, count);
    } else {
      rv = net_mod_socket_sub(gNetmod_socket, topics_buf, count);
    }
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    free(topics_buf);
    pthread_mutex_unlock(&mutex);
  } else {
    rv = EBUS_RES_BUSY;
    rv = EBUS_NO_MEM;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    
    logger->error("in BHSubscribeTopics: Out of memory!\n");
    return false;
  }
  memset(topics_buf, 0x00, total);
#if defined(PRO_DE_SERIALIZE)
  for (i = 0; i < _input.amount; i++) {
    len = strlen(_input.topics[i]);
    strncpy(topics_buf + count, _input.topics[i], len);
    count += len;
    if ((_input.amount > 1) && (i < (_input.amount - 1))) {
      strncpy(topics_buf + count, STR_MAGIC, strlen(STR_MAGIC));
      count++;
    }
  }
#else
  memcpy(topics_buf, topics, topics_len);
  count = topics_len;
#endif
  if (timeout_ms > 0) {
    sec = timeout_ms / 1000;
    nsec = (timeout_ms - sec * 1000) * 1000 * 1000;
    rv = net_mod_socket_sub_timeout(gNetmod_socket, topics_buf, count, sec, nsec);
  } else if (timeout_ms == 0) {
    rv = net_mod_socket_sub_nowait(gNetmod_socket, topics_buf, count);
  } else {
    rv = net_mod_socket_sub(gNetmod_socket, topics_buf, count);
  }
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
  free(topics_buf);
#if defined(PRO_DE_SERIALIZE)
  ::bhome_msg::MsgCommonReply mcr;
@@ -932,8 +881,8 @@
  ::bhome_msg::MsgCommonReply mcr;
   mcr.mutable_errmsg()->set_errcode(::bhome_msg::ErrorCode(rv));
   mcr.mutable_errmsg()->set_errstring(errString);
   *reply_len=mcr.ByteSizeLong();
   *reply=malloc(*reply_len);
   *reply_len = mcr.ByteSizeLong();
   *reply = malloc(*reply_len);
   mcr.SerializePartialToArray(*reply,*reply_len);
#endif 
@@ -991,46 +940,35 @@
    return false;
  }
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
#if defined(PRO_DE_SERIALIZE)
    if (timeout_ms > 0) {
      rv = net_mod_socket_pub_timeout(gNetmod_socket, &node_arr, node_arr_len, _input.topic, strlen(_input.topic), _input.data, strlen(_input.data), timeout_ms);
    } else if (timeout_ms == 0) {
      rv = net_mod_socket_pub_nowait(gNetmod_socket, &node_arr, node_arr_len, _input.topic, strlen(_input.topic), _input.data, strlen(_input.data));
    } else {
      rv = net_mod_socket_pub(gNetmod_socket, &node_arr, node_arr_len, _input.topic, strlen(_input.topic), _input.data, strlen(_input.data));
    }
#else
    if (timeout_ms > 0) {
      rv = net_mod_socket_pub_timeout(gNetmod_socket, &node_arr, node_arr_len, topic, strlen(topic), content, strlen(content), timeout_ms);
    } else if (timeout_ms == 0) {
      rv = net_mod_socket_pub_nowait(gNetmod_socket, &node_arr, node_arr_len, topic, strlen(topic), content, strlen(content));
  if (timeout_ms > 0) {
    rv = net_mod_socket_pub_timeout(gNetmod_socket, &node_arr, node_arr_len, _input.topic, strlen(_input.topic), _input.data, strlen(_input.data), timeout_ms);
  } else if (timeout_ms == 0) {
    rv = net_mod_socket_pub_nowait(gNetmod_socket, &node_arr, node_arr_len, _input.topic, strlen(_input.topic), _input.data, strlen(_input.data));
    
    } else {
      rv = net_mod_socket_pub(gNetmod_socket, &node_arr, node_arr_len, topic, strlen(topic), content, strlen(content));
    }
  } else {
    rv = net_mod_socket_pub(gNetmod_socket, &node_arr, node_arr_len, _input.topic, strlen(_input.topic), _input.data, strlen(_input.data));
  }
#else
  if (timeout_ms > 0) {
    rv = net_mod_socket_pub_timeout(gNetmod_socket, &node_arr, node_arr_len, topic, strlen(topic), content, strlen(content), timeout_ms);
  } else if (timeout_ms == 0) {
    rv = net_mod_socket_pub_nowait(gNetmod_socket, &node_arr, node_arr_len, topic, strlen(topic), content, strlen(content));
  } else {
    rv = net_mod_socket_pub(gNetmod_socket, &node_arr, node_arr_len, topic, strlen(topic), content, strlen(content));
  }
#endif 
    pthread_mutex_unlock(&mutex);
    if (rv > 0)
      return true;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
  } else {
    rv = EBUS_RES_BUSY;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
  }
  if (rv > 0)
    return true;
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
  return false;
}
@@ -1042,8 +980,9 @@
  int key;
  int size;
  int sec, nsec;
  char topics_buf[MAX_STR_LEN] = { 0x00 };
  char data_buf[MAX_STR_LEN * 3] = { 0x00 };
  char buf_temp[100] = { 0x00 };
  char *topics_buf = NULL;
  char *data_buf = NULL;
  struct _ReadSubReply
  {
@@ -1091,11 +1030,40 @@
    if (len > size) {
      len = size;
    }
    strncpy(topics_buf, (char *)buf, len > (sizeof(topics_buf) - 1) ? (sizeof(topics_buf) - 1) : len);
    topics_buf = (char *)malloc(len + 10);
    if (topics_buf == NULL) {
      rv = EBUS_NO_MEM;
      memset(errString, 0x00, sizeof(errString));
      strncpy(errString, bus_strerror(rv), sizeof(errString));
      logger->error("in BHRequest: Out of memory!\n");
      return false;
    }
    memset(topics_buf, 0x00, len + 10);
    strncpy(topics_buf, (char *)buf, len);
    
    if (len < size) {
      len = strlen(topics_buf) + 1;
      data_buf = (char *)malloc(size - len + 10);
      if (data_buf == NULL) {
        rv = EBUS_NO_MEM;
        memset(errString, 0x00, sizeof(errString));
        strncpy(errString, bus_strerror(rv), sizeof(errString));
        logger->error("in BHRequest: Out of memory!\n");
        free(topics_buf);
        return false;
      }
      memset(data_buf, 0x00, size - len + 10);
      len = strlen(topics_buf) + 1;
      strncpy(data_buf, (char *)buf + len, size - len);
    }
@@ -1103,17 +1071,23 @@
#if defined(PRO_DE_SERIALIZE)
    rsr.topic = topics_buf;
    rsr.data = data_buf;
    if (data_buf != NULL) {
      rsr.data = data_buf;
    } else {
      rsr.data = topics_buf;
    }
    memset(topics_buf, 0x00, sizeof(topics_buf));
    sprintf(topics_buf, "%d", key);
    sprintf(buf_temp, "%d", key);
    if ((proc_id != NULL) && (proc_id_len != NULL)) {
      rsr.proc_id = topics_buf;
      rsr.proc_id = buf_temp;
      *proc_id_len = rsr.proc_id.size();
      *proc_id = malloc(*proc_id_len);
      memcpy(*proc_id, rsr.proc_id.data(), *proc_id_len);
    }
    free(topics_buf);
    free(data_buf);
    ::bhome_msg::MsgPublish Mp; 
    Mp.set_topic(rsr.topic);
@@ -1133,14 +1107,17 @@
    }
    *msgpub = ptr;
    *msgpub_len = len;
    free(topics_buf);
    free(data_buf);
    if ((proc_id != NULL) && (proc_id_len != NULL)) {
      memset(topics_buf, 0x00, sizeof(topics_buf));
      sprintf(topics_buf, "%d", key);
      memset(buf_temp, 0x00, sizeof(buf_temp));
      sprintf(buf_temp, "%d", key);
      
      *proc_id_len = strlen(topics_buf);
      *proc_id_len = strlen(buf_temp);
      *proc_id = malloc(*proc_id_len);
      memcpy(*proc_id, topics_buf, *proc_id_len);
      memcpy(*proc_id, buf_temp, *proc_id_len);
    }
    
#endif 
@@ -1165,6 +1142,7 @@
  int val;
  int len;
  int min;
  int data;
  int sec, nsec;
  std::string MsgID;
  int timeout_ms = 3000;
@@ -1225,89 +1203,78 @@
    return false;
  }
 
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
#if defined(PRO_DE_SERIALIZE)
    strncpy(buf_temp, _input1.topic, (sizeof(buf_temp) - 1) > strlen(_input1.topic) ? strlen(_input1.topic) : (sizeof(buf_temp) - 1));
  strncpy(buf_temp, _input1.topic, (sizeof(buf_temp) - 1) > strlen(_input1.topic) ? strlen(_input1.topic) : (sizeof(buf_temp) - 1));
#else 
    strncpy(buf_temp, (char *)request, (sizeof(buf_temp) - 1) > strlen((char *)request) ? strlen((char *)request) : (sizeof(buf_temp) - 1));
  strncpy(buf_temp, (char *)request, (sizeof(buf_temp) - 1) > strlen((char *)request) ? strlen((char *)request) : (sizeof(buf_temp) - 1));
#endif 
    rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
    if (rv == 0) {
  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);
    val = atoi((char *)buf);
      free(buf);
    free(buf);
      if (val > 0) {
    if (val > 0) {
        len = strlen(buf_temp) + 1;
      len = strlen(buf_temp) + 1;
#if defined(PRO_DE_SERIALIZE)
        len += strlen(_input1.data);
      len += strlen(_input1.data);
#endif
        topics_buf = (char *)malloc(len);
        if (topics_buf == NULL) {
          rv = EBUS_NO_MEM;
          memset(errString, 0x00, sizeof(errString));
          strncpy(errString, bus_strerror(rv), sizeof(errString));
          logger->error("in BHRequest: Out of memory!\n");
          pthread_mutex_unlock(&mutex);
          return false;
        }
        memset(topics_buf, 0x00, len);
      topics_buf = (char *)malloc(len);
      if (topics_buf == NULL) {
        
        strncpy(topics_buf, buf_temp, strlen(buf_temp) + 1);
        rv = EBUS_NO_MEM;
        memset(errString, 0x00, sizeof(errString));
        strncpy(errString, bus_strerror(rv), sizeof(errString));
        logger->error("in BHRequest: Out of memory!\n");
        return false;
      }
      memset(topics_buf, 0x00, len);
      strncpy(topics_buf, buf_temp, strlen(buf_temp) + 1);
#if defined(PRO_DE_SERIALIZE)
        strncpy(topics_buf + strlen(buf_temp) + 1, _input1.data, strlen(_input1.data));
      strncpy(topics_buf + strlen(buf_temp) + 1, _input1.data, strlen(_input1.data));
#endif 
        if (timeout_ms > 0) {
      data = net_mod_socket_svr_get(gNetmod_socket);
      if (timeout_ms > 0) {
          sec = timeout_ms / 1000;
          nsec = (timeout_ms - sec * 1000) * 1000 * 1000;
          rv = net_mod_socket_sendto_timeout(gNetmod_socket, topics_buf, len, val, sec, nsec);
        } else if (timeout_ms == 0) {
          rv = net_mod_socket_sendto_nowait(gNetmod_socket, topics_buf, len, val);
        } else {
          rv = net_mod_socket_sendto(gNetmod_socket, topics_buf, len, val);
        }
        free(topics_buf);
        sec = timeout_ms / 1000;
        nsec = (timeout_ms - sec * 1000) * 1000 * 1000;
        
        rv = net_mod_socket_sendto_timeout(gNetmod_socket, topics_buf, len, val, sec, nsec, SVR_STR, data);
      } else if (timeout_ms == 0) {
        rv = net_mod_socket_sendto_nowait(gNetmod_socket, topics_buf, len, val, SVR_STR, data);
      } else {
        rv = EBUS_RES_UNSUPPORT;
      }
    }
        rv = net_mod_socket_sendto(gNetmod_socket, topics_buf, len, val, SVR_STR, data);
      }
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    pthread_mutex_unlock(&mutex);
    if((msg_id == NULL) || (msg_id_len == NULL)) {
      if (rv == 0)
        return true;
      free(topics_buf);
      
      return false;
    }
  } else {
    } else {
    rv = EBUS_RES_BUSY;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
      rv = EBUS_RES_UNSUPPORT;
    }
  }
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
  if((msg_id == NULL) || (msg_id_len == NULL)) {
    if (rv == 0)
      return true;
    return false;
  }
  
  if (rv == 0) {
@@ -1335,6 +1302,7 @@
  int size;
  int val;
  int min, len;
  int data;
  net_node_t node;
  int node_size;  
  int recv_arr_size;
@@ -1404,115 +1372,29 @@
    return false;
  }
  
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
#if defined(PRO_DE_SERIALIZE)
    strncpy(buf_temp, _input1.topic, (sizeof(buf_temp) - 1) > strlen(_input1.topic) ? strlen(_input1.topic)  : (sizeof(buf_temp) - 1));
  strncpy(buf_temp, _input1.topic, (sizeof(buf_temp) - 1) > strlen(_input1.topic) ? strlen(_input1.topic)  : (sizeof(buf_temp) - 1));
#else 
    strncpy(buf_temp, (char *)request, (sizeof(buf_temp) - 1) > request_len ? request_len : (sizeof(buf_temp) - 1));
  strncpy(buf_temp, (char *)request, (sizeof(buf_temp) - 1) > request_len ? request_len : (sizeof(buf_temp) - 1));
#endif 
  rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
  if (rv == 0) {
    
    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);
    free(buf);
    if (val > 0) {
      memset(&node, 0x00, sizeof(node));
      
      val = atoi((char *)buf);
      free(buf);
      if (val > 0) {
        memset(&node, 0x00, sizeof(node));
        len = strlen(buf_temp) + 1;
      len = strlen(buf_temp) + 1;
#if defined(PRO_DE_SERIALIZE)
        len += strlen(_input1.data);
      len += strlen(_input1.data);
#endif
        topics_buf = (char *)malloc(len);
        if (topics_buf == NULL) {
          rv = EBUS_NO_MEM;
          memset(errString, 0x00, sizeof(errString));
          strncpy(errString, bus_strerror(rv), sizeof(errString));
          logger->error("in BHRequest: Out of memory!\n");
          pthread_mutex_unlock(&mutex);
          return false;
        }
        memset(topics_buf, 0x00, len);
        strncpy(topics_buf, buf_temp, strlen(buf_temp) + 1);
#if defined(PRO_DE_SERIALIZE)
        strncpy(topics_buf + strlen(buf_temp) + 1, _input1.data, strlen(_input1.data));
#endif
        node.key = val;
        if (timeout_ms > 0) {
          rv = net_mod_socket_sendandrecv_timeout(gNetmod_socket, &node, 1, topics_buf, len, &recv_arr, &recv_arr_size, &errarr, &errarr_size, timeout_ms);
        } else if (timeout_ms == 0) {
          rv = net_mod_socket_sendandrecv_nowait(gNetmod_socket, &node, 1, topics_buf, len, &recv_arr, &recv_arr_size, &errarr, &errarr_size);
        } else {
          rv = net_mod_socket_sendandrecv(gNetmod_socket, &node, 1, topics_buf, len, &recv_arr, &recv_arr_size, &errarr, &errarr_size);
        }
        if (rv > 0) {
          if (recv_arr_size > 0) {
            node.key = recv_arr[0].key;
            size = recv_arr[0].content_length;
            buf = (char *)malloc(size);
            if (buf == NULL) {
              printf("Out of memory\n");
              exit(0);
            }
            memset((char *)buf, 0x00, size);
            strncpy((char *)buf, (char *)recv_arr[0].content, size);
          }
          net_mod_socket_free_recv_msg_arr(recv_arr, recv_arr_size);
          if(errarr_size > 0) {
            free(errarr);
          }
          rv = 0;
        } else {
          rv = EBUS_TIMEOUT;
        }
      } else {
        rv = EBUS_RES_UNSUPPORT;
      }
      free(topics_buf);
    }
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    if (rv == 0) {
      if ((proc_id != NULL) && (proc_id_len != NULL)) {
        memset(buf_temp, 0x00, sizeof(buf_temp));
        sprintf(buf_temp, "%d", node.key);
        rr.proc_id = buf_temp;
        *proc_id_len = rr.proc_id.size();
        *proc_id = malloc(*proc_id_len);
        memcpy(*proc_id, rr.proc_id.c_str(), *proc_id_len);
      }
      topics_buf = (char *)malloc(size);
      data = net_mod_socket_svr_get(gNetmod_socket);
      topics_buf = (char *)malloc(len);
      if (topics_buf == NULL) {
        
        rv = EBUS_NO_MEM;
@@ -1521,26 +1403,98 @@
        
        logger->error("in BHRequest: Out of memory!\n");
        
        pthread_mutex_unlock(&mutex);
        return false;
      }
      memset(topics_buf, 0x00, size);
      memset(topics_buf, 0x00, len);
      
      memcpy(topics_buf, buf, size);
      rr.data = topics_buf;
      free(buf);
      free(topics_buf);
    }
    pthread_mutex_unlock(&mutex);
      strncpy(topics_buf, buf_temp, strlen(buf_temp) + 1);
#if defined(PRO_DE_SERIALIZE)
      strncpy(topics_buf + strlen(buf_temp) + 1, _input1.data, strlen(_input1.data));
#endif
  } else {
    rv = EBUS_RES_BUSY;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
      node.key = val;
      if (timeout_ms > 0) {
        rv = net_mod_socket_sendandrecv_timeout(gNetmod_socket, &node, 1, topics_buf, len, &recv_arr, &recv_arr_size, &errarr, &errarr_size, timeout_ms);
      } else if (timeout_ms == 0) {
        rv = net_mod_socket_sendandrecv_nowait(gNetmod_socket, &node, 1, topics_buf, len, &recv_arr, &recv_arr_size, &errarr, &errarr_size);
      } else {
        rv = net_mod_socket_sendandrecv(gNetmod_socket, &node, 1, topics_buf, len, &recv_arr, &recv_arr_size, &errarr, &errarr_size);
      }
      if (rv > 0) {
        if (recv_arr_size > 0) {
          node.key = recv_arr[0].key;
          size = recv_arr[0].content_length;
          buf = (char *)malloc(size);
          if (buf == NULL) {
            printf("Out of memory\n");
            exit(0);
          }
          memset((char *)buf, 0x00, size);
          strncpy((char *)buf, (char *)recv_arr[0].content, size);
        }
        net_mod_socket_free_recv_msg_arr(recv_arr, recv_arr_size);
        if(errarr_size > 0) {
          free(errarr);
        }
        rv = 0;
      } else {
        rv = EBUS_TIMEOUT;
      }
    } else {
      rv = EBUS_RES_UNSUPPORT;
    }
    free(topics_buf);
  }
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
  if (rv == 0) {
    if ((proc_id != NULL) && (proc_id_len != NULL)) {
      memset(buf_temp, 0x00, sizeof(buf_temp));
      sprintf(buf_temp, "%d", node.key);
      rr.proc_id = buf_temp;
      *proc_id_len = rr.proc_id.size();
      *proc_id = malloc(*proc_id_len);
      memcpy(*proc_id, rr.proc_id.c_str(), *proc_id_len);
    }
    topics_buf = (char *)malloc(size + 10);
    if (topics_buf == NULL) {
      rv = EBUS_NO_MEM;
      memset(errString, 0x00, sizeof(errString));
      strncpy(errString, bus_strerror(rv), sizeof(errString));
      logger->error("in BHRequest: Out of memory!\n");
      return false;
    }
    memset(topics_buf, 0x00, size + 10);
    memcpy(topics_buf, buf, size);
    rr.data = topics_buf;
    free(buf);
    free(topics_buf);
  }
#if defined(PRO_DE_SERIALIZE) 
@@ -1578,6 +1532,7 @@
  int key;
  int size;
  int len;
  int data;
  int sec, nsec;
  char buf_temp[MAX_STR_LEN] = { 0x00 };
  char *topics_buf = NULL;
@@ -1600,20 +1555,21 @@
      return false;
  }
  data = net_mod_socket_svr_get(gNetmod_socket);
  if (timeout_ms > 0) {
    sec = timeout_ms / 1000;
    nsec = (timeout_ms - sec * 1000) * 1000 * 1000;
    rv = net_mod_socket_recvfrom_timeout(gNetmod_socket, &buf, &size, &key, sec, nsec);
    rv = net_mod_socket_recvfrom_timeout(gNetmod_socket, &buf, &size, &key, sec, nsec, SVR_STR, data);
  } else if (timeout_ms == 0) {
    rv = net_mod_socket_recvfrom_nowait(gNetmod_socket, &buf, &size, &key);
    rv = net_mod_socket_recvfrom_nowait(gNetmod_socket, &buf, &size, &key, SVR_STR, data);
  
  } else {
    rv = net_mod_socket_recvfrom(gNetmod_socket, &buf, &size, &key);
    rv = net_mod_socket_recvfrom(gNetmod_socket, &buf, &size, &key, SVR_STR, data);
  }
  if (rv == 0) {
@@ -1693,6 +1649,7 @@
int BHSendReply(void *src, const void *reply, const int reply_len)
{
  int rv;
  int data;
  const char *_input;
  
#if defined(PRO_DE_SERIALIZE)
@@ -1732,21 +1689,11 @@
    return false;
  }
  rv = pthread_mutex_trylock(&mutex);
  if (rv == 0) {
  data = net_mod_socket_svr_get(gNetmod_socket);
  rv = net_mod_socket_sendto(gNetmod_socket, _input, strlen(_input), *(int *)src, SVR_STR, data);
    rv = net_mod_socket_sendto(gNetmod_socket, _input, strlen(_input), *(int *)src);
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
    pthread_mutex_unlock(&mutex);
  } else {
    rv = EBUS_RES_BUSY;
    memset(errString, 0x00, sizeof(errString));
    strncpy(errString, bus_strerror(rv), sizeof(errString));
  }
  memset(errString, 0x00, sizeof(errString));
  strncpy(errString, bus_strerror(rv), sizeof(errString));
  
  if (rv == 0)
    return true;