Fu Juntang
2021-09-17 5c912c70e9333298ff48f7ea15424f72ca977b99
src/bus_proxy_start.cpp
@@ -11,9 +11,13 @@
#include <getopt.h>
#include <stdlib.h>
using namespace std;
#define SVR_PORT            5000
#define TOTAL_THREADS       2
#define TOTAL_THREADS       3
#define MAX_RETRIES         3
static void *gBusServer_socket = NULL;
static void *gServer_socket = NULL;
@@ -24,8 +28,10 @@
static int gBusServer_act = 0;
static int gBusServer_stat = 0;
pthread_t tids[2];
void *res[2];
pthread_t tids[TOTAL_THREADS];
void *res[TOTAL_THREADS];
extern list gLinkedList;
void *bus_start(void *skptr) {
@@ -48,6 +54,58 @@
  gServer_socket  = net_mod_server_socket_open(port);
  if(net_mod_server_socket_start(gServer_socket) != 0) {
    printf("start net mod server failed\n");
  }
  return NULL;
}
void *check_start(void *skptr) {
  int i;
  int ret;
  int val;
  int thres;
  int data;
  int data_ret;
  int total;
  void *buf;
  int size;
  char buf_temp[MAX_STR_LEN] = { 0x00 };
  struct timespec timeout = {.tv_sec = 3, .tv_nsec = 0};
  while(true) {
    total = gLinkedList.NodeNum();
    for (i = 0; i < total; i++) {
      val = gLinkedList.nodeGet(i);
      if (val > 0) {
        data_ret = bus_server_socket_wrapper_data_get(gBusServer_socket, val);
        thres = gLinkedList.dataGet(val);
        if ((data_ret == true) && (thres < MAX_RETRIES)) {
          data = gLinkedList.dataFixGet(val);
          sprintf(buf_temp, "%d", i + 1);
          ret = bus_server_socket_wrapper_proc_check(gBusServer_socket, data, buf_temp, strlen(buf_temp), &buf, &size, &timeout, BUS_TIMEOUT_FLAG);
          if (ret == 0) {
            gLinkedList.dataSet(val, 0x00);
            free(buf);
          } else {
            gLinkedList.dataSet(val, ++thres);
          }
        } else {
          gLinkedList.Delete(val);
          if (thres >= MAX_RETRIES) {
            bus_server_socket_wrapper_proc_release(gBusServer_socket, val);
          }
        }
      }
    }
    sleep(10);
  }
  return NULL;
@@ -110,6 +168,8 @@
  if (gBusServer_stat >= 0) { 
    pthread_create(&tids[1], NULL, svr_start, (void *)&gPort);
    pthread_create(&tids[0], NULL, check_start, NULL);
  }
  for (i = 0; i< TOTAL_THREADS; i++) {