| | |
| | | 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); |
| | | if (shm_sendto(shm_socket, buf, size, send_key, &timeout) == EBUS_CLOSED ) { |
| | | // logger->debug("_proxy_pub send before %d \n", send_key); |
| | | if (shm_sendto(shm_socket, buf, size, send_key, &timeout, BUS_TIMEOUT_FLAG) == EBUS_CLOSED ) { |
| | | //对方已关闭的连接放到待删除队列里。如果直接删除会让iter指针出现错乱 |
| | | subscripter_to_del.push_back(send_key); |
| | | } else { |
| | | // printf("_proxy_pub send after: %d \n", send_key); |
| | | // logger->debug("_proxy_pub send after: %d \n", send_key); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | // 删除已关闭的端 |
| | |
| | | bus_head_t head; |
| | | |
| | | const char *topic_delim = ","; |
| | | // printf("run_pubsub_proxy server receive before\n"); |
| | | // logger.debug("run_pubsub_proxy server receive before\n"); |
| | | while(shm_recvfrom(shm_socket, (void **)&buf, &size, &key) == 0) { |
| | | // printf("run_pubsub_proxy server recvfrom %d after: %s \n", key, buf); |
| | | // logger.debug("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\n", action); |
| | | // logger.debug("run_pubsub_proxy : %s\n", action); |
| | | if(strcmp(action, "sub") == 0) { |
| | | // 订阅支持多主题订阅 |
| | | topic = strtok(topics, topic_delim); |
| | | // printf("run_pubsub_proxy topic = %s\n", topic); |
| | | // logger.debug("run_pubsub_proxy topic = %s\n", topic); |
| | | while(topic) { |
| | | _proxy_sub(trim(topic, 0), key); |
| | | topic = strtok(NULL, topic_delim); |
| | |
| | | |
| | | } |
| | | else if(strcmp(action, "desub") == 0) { |
| | | // printf("desub topic=%s,%s,%d\n", topics, trim(topics, 0), strcmp(trim(topics, 0), "")); |
| | | // logger.debug("desub topic=%s,%s,%d\n", topics, trim(topics, 0), strcmp(trim(topics, 0), "")); |
| | | if(strcmp(trim(topics, 0), "") == 0) { |
| | | // 取消所有订阅 |
| | | _proxy_desub_all(key); |