| | |
| | | } |
| | | } |
| | | return count; |
| | | // foreach_subscripters([keys, length, &count](SHMKeySet *subscripter_set, int key){ |
| | | // printf("foreach===========\n"); |
| | | // if (include_in_keys(key, keys, length)) { |
| | | |
| | | // //subscripter_set->erase(key); |
| | | // printf("remove_subscripter %d\n", key); |
| | | // count++; |
| | | // } |
| | | // }); |
| | | // printf("remove_subscripters count = %d\n", count); |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | DModSocket::DModSocket() { |
| | | shm_socket = shm_open_socket(SHM_SOCKET_DGRAM); |
| | | bus_set = new std::set<int>; |
| | | mod = (socket_mod_t)0; |
| | | shm_socket = shm_open_socket(SHM_SOCKET_DGRAM); |
| | | bus_set = new std::set<int>; |
| | | topic_sub_map = NULL; |
| | | } |
| | | |
| | | DModSocket::~DModSocket() { |
| | | // printf("DModSocket destory 1\n"); |
| | | SHMKeySet *subscripter_set; |
| | | SHMTopicSubMap::iterator map_iter; |
| | | struct timespec timeout = {1, 0}; |
| | | if(bus_set != NULL) { |
| | | for(auto bus_iter = bus_set->begin(); bus_iter != bus_set->end(); bus_iter++) { |
| | | desub_timeout(NULL, 0, *bus_iter, &timeout); |
| | | // printf("DModSocket desub_timeout before"); |
| | | // desub_timeout(NULL, 0, *bus_iter, &timeout); |
| | | // printf("DModSocket desub_timeout after %d\n", *bus_iter); |
| | | } |
| | | delete bus_set; |
| | | } |
| | | |
| | | // printf("DModSocket destory 2\n"); |
| | | if(topic_sub_map != NULL) { |
| | | for (map_iter = topic_sub_map->begin(); map_iter != topic_sub_map->end(); map_iter++) { |
| | | subscripter_set = map_iter->second; |
| | | subscripter_set->clear(); |
| | | mm_free((void *)subscripter_set); |
| | | //delete subscripter_set; |
| | | // printf("=============delete subscripter_set\n"); |
| | | // printf("DModSocket destory 2-1\n"); |
| | | if(subscripter_set != NULL) { |
| | | // printf("DModSocket destory 2-2\n"); |
| | | subscripter_set->clear(); |
| | | // printf("DModSocket destory 2-3\n"); |
| | | mm_free((void *)subscripter_set); |
| | | // printf("DModSocket destory 2-4\n"); |
| | | } |
| | | |
| | | } |
| | | topic_sub_map->clear(); |
| | | mem_pool_free_by_key(BUS_MAP_KEY); |
| | | } |
| | | // printf("DModSocket destory 3\n"); |
| | | // printf("=============close socket\n"); |
| | | shm_close_socket(shm_socket); |
| | | // printf("DModSocket destory 4\n"); |
| | | } |
| | | |
| | | int DModSocket::bind(int port) { |