| | |
| | | #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; |
| | |
| | | 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) { |
| | | |
| | |
| | | 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; |
| | |
| | | |
| | | 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++) { |