From c46be6db32872bfd7c4010b43526b5e6bc0fa6a5 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 25 一月 2021 14:04:59 +0800 Subject: [PATCH] update --- src/socket/bus_server_socket.cpp | 132 ++++++++++++++++++++++---------------------- 1 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/socket/bus_server_socket.cpp b/src/socket/bus_server_socket.cpp index 9bd61b0..e66a709 100644 --- a/src/socket/bus_server_socket.cpp +++ b/src/socket/bus_server_socket.cpp @@ -6,7 +6,7 @@ static Logger *logger = LoggerFactory::getLogger(); void BusServerSocket::foreach_subscripters(std::function<void(SHMKeySet *, int)> cb) { - SHMTopicSubMap *topic_sub_map = mem_pool_attach<SHMTopicSubMap>(BUS_MAP_KEY); + SHMTopicSubMap *topic_sub_map = mem_pool_attach<SHMTopicSubMap>(SHM_BUS_MAP_KEY); SHMKeySet *subscripter_set; SHMKeySet::iterator set_iter; SHMTopicSubMap::iterator map_iter; @@ -39,7 +39,7 @@ int key; for(int i = 0; i < length; i++) { key = keys[i]; - SHMTopicSubMap *topic_sub_map = mem_pool_attach<SHMTopicSubMap>(BUS_MAP_KEY); + SHMTopicSubMap *topic_sub_map = mem_pool_attach<SHMTopicSubMap>(SHM_BUS_MAP_KEY); SHMKeySet *subscripter_set; SHMKeySet::iterator set_iter; SHMTopicSubMap::iterator map_iter; @@ -85,7 +85,7 @@ } topic_sub_map->clear(); - mem_pool_free_by_key(BUS_MAP_KEY); + mem_pool_free_by_key(SHM_BUS_MAP_KEY); } shm_close_socket(shm_socket); logger->debug("BusServerSocket destory 3"); @@ -111,7 +111,7 @@ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 */ int BusServerSocket::start(){ - topic_sub_map = mem_pool_attach<SHMTopicSubMap>(BUS_MAP_KEY); + topic_sub_map = mem_pool_attach<SHMTopicSubMap>(SHM_BUS_MAP_KEY); run_pubsub_proxy(); // 杩涚▼鍋滄鐨勬椂鍊欙紝棰勭暀3绉掕祫婧愬洖鏀剁殑鏃堕棿銆傚惁鍒欙紝浼氬彂鐢熻皟鐢╟lose鐨勬椂鍊欙紝鍏变韩鍐呭瓨鐨勮祫婧愯繕娌℃潵寰楀強鍥炴敹杩涚▼灏遍��鍑轰簡 @@ -212,12 +212,12 @@ subscripter_set = map_iter->second; for(set_iter = subscripter_set->begin(); set_iter != subscripter_set->end(); set_iter++) { send_key = *set_iter; - // printf("_proxy_pub send before %d \n", send_key); + printf("_proxy_pub send before %d \n", send_key); if (shm_sendto(shm_socket, buf, size, send_key, &timeout) == EBUS_CLOSED ) { //瀵规柟宸插叧闂殑杩炴帴鏀惧埌寰呭垹闄ら槦鍒楅噷銆傚鏋滅洿鎺ュ垹闄や細璁﹊ter鎸囬拡鍑虹幇閿欎贡 subscripter_to_del.push_back(send_key); } else { -// printf("_proxy_pub send after: %d \n", send_key); +printf("_proxy_pub send after: %d \n", send_key); } @@ -247,15 +247,15 @@ const char *topic_delim = ","; // printf("run_pubsub_proxy server receive before\n"); while(shm_recvfrom(shm_socket, (void **)&buf, &size, &key) == 0) { -//printf("run_pubsub_proxy server recv after: %s \n", buf); +printf("run_pubsub_proxy server recvfrom %d after: %s \n", key, buf); head = ShmModSocket::decode_bus_head(buf); topics = buf + BUS_HEAD_SIZE; action = head.action; - // printf("run_pubsub_proxy : %s, %s \n", action, topics); + printf("run_pubsub_proxy : %s, %s \n", action, topics); if(strcmp(action, "sub") == 0) { // 璁㈤槄鏀寔澶氫富棰樿闃� topic = strtok(topics, topic_delim); -//printf("run_pubsub_proxy topic = %s\n", topic); +printf("run_pubsub_proxy topic = %s\n", topic); while(topic) { _proxy_sub(trim(topic, 0), key); topic = strtok(NULL, topic_delim); @@ -301,71 +301,71 @@ -/** - * deprecate - * @str "<**sub**>{缁忔祹}" - */ +// /** +// * deprecate +// * @str "<**sub**>{缁忔祹}" +// */ -int BusServerSocket::parse_pubsub_topic(char *str, size_t size, char **_action, char **_topic, size_t *head_len ) { - char *ptr = str; - char *str_end_ptr = str + size; - char *action_start_ptr; - char *action_end_ptr; - size_t action_len = 0; +// int BusServerSocket::parse_pubsub_topic(char *str, size_t size, char **_action, char **_topic, size_t *head_len ) { +// char *ptr = str; +// char *str_end_ptr = str + size; +// char *action_start_ptr; +// char *action_end_ptr; +// size_t action_len = 0; - char *topic_start_ptr; - char *topic_end_ptr; - size_t topic_len = 0; +// char *topic_start_ptr; +// char *topic_end_ptr; +// size_t topic_len = 0; - // if (strlen(identifier) > strlen(str)) { - // return 0; - // } +// // if (strlen(identifier) > strlen(str)) { +// // return 0; +// // } - if (strncmp(ptr, ACTION_LIDENTIFIER, strlen(ACTION_LIDENTIFIER)) == 0) { - ptr += strlen(ACTION_LIDENTIFIER); - action_start_ptr = ptr; - while(strncmp(++ptr, ACTION_RIDENTIFIER, strlen(ACTION_RIDENTIFIER)) != 0) { - if(ptr >= str_end_ptr) { - return 0; - } - } -// printf("%s\n", ptr); - action_end_ptr = ptr; - action_len = action_end_ptr - action_start_ptr; - ptr += strlen(ACTION_RIDENTIFIER); -// printf("%s\n", ptr); -// printf("%s\n", str_end_ptr-1); - if(strncmp(ptr, TOPIC_LIDENTIFIER, strlen(TOPIC_LIDENTIFIER)) == 0 ) { - topic_start_ptr = ptr+strlen(TOPIC_LIDENTIFIER); +// if (strncmp(ptr, ACTION_LIDENTIFIER, strlen(ACTION_LIDENTIFIER)) == 0) { +// ptr += strlen(ACTION_LIDENTIFIER); +// action_start_ptr = ptr; +// while(strncmp(++ptr, ACTION_RIDENTIFIER, strlen(ACTION_RIDENTIFIER)) != 0) { +// if(ptr >= str_end_ptr) { +// return 0; +// } +// } +// // printf("%s\n", ptr); +// action_end_ptr = ptr; +// action_len = action_end_ptr - action_start_ptr; +// ptr += strlen(ACTION_RIDENTIFIER); +// // printf("%s\n", ptr); +// // printf("%s\n", str_end_ptr-1); +// if(strncmp(ptr, TOPIC_LIDENTIFIER, strlen(TOPIC_LIDENTIFIER)) == 0 ) { +// topic_start_ptr = ptr+strlen(TOPIC_LIDENTIFIER); - while(strncmp(++ptr, TOPIC_RIDENTIFIER, strlen(TOPIC_RIDENTIFIER)) != 0) { - if(ptr >= str_end_ptr) { - return 0; - } - } - topic_end_ptr = ptr; - topic_len = topic_end_ptr - topic_start_ptr; +// while(strncmp(++ptr, TOPIC_RIDENTIFIER, strlen(TOPIC_RIDENTIFIER)) != 0) { +// if(ptr >= str_end_ptr) { +// return 0; +// } +// } +// topic_end_ptr = ptr; +// topic_len = topic_end_ptr - topic_start_ptr; - ptr += strlen(TOPIC_RIDENTIFIER); +// ptr += strlen(TOPIC_RIDENTIFIER); - } else { - return 0; - } - } else { - return 0; - } +// } else { +// return 0; +// } +// } else { +// return 0; +// } - char *topic = (char *)malloc(topic_len+1); - strncpy(topic, topic_start_ptr, topic_len); - *(topic+topic_len) = '\0'; - *_topic = topic; +// char *topic = (char *)malloc(topic_len+1); +// strncpy(topic, topic_start_ptr, topic_len); +// *(topic+topic_len) = '\0'; +// *_topic = topic; - char *action = (char *)malloc(action_len+1); - strncpy(action, action_start_ptr, action_len); - *(action+action_len) = '\0'; - *_action = action; - *head_len = ptr-str; +// char *action = (char *)malloc(action_len+1); +// strncpy(action, action_start_ptr, action_len); +// *(action+action_len) = '\0'; +// *_action = action; +// *head_len = ptr-str; - return 1; -} \ No newline at end of file +// return 1; +// } \ No newline at end of file -- Gitblit v1.8.0