diff --git a/connection.cpp b/connection.cpp index c169fb2..6f42dc5 100644 --- a/connection.cpp +++ b/connection.cpp @@ -215,6 +215,11 @@ conn_manager_t conn_manager; if(it==mp.end()) { mp[addr]=new conn_info_t; + //lru.new_key(addr); + } + else + { + //lru.update(addr); } return mp[addr]; } @@ -228,6 +233,11 @@ conn_manager_t conn_manager; if(it==mp.end()) { mp[addr]=new conn_info_t; + //lru.new_key(addr); + } + else + { + //lru.update(addr); } return *mp[addr]; } @@ -282,14 +292,14 @@ int conn_manager_t::clear_inactive() } int conn_manager_t::clear_inactive0() { - //unordered_map::iterator it; - // unordered_map::iterator old_it; + unordered_map::iterator it; + unordered_map::iterator old_it; if(disable_conn_clear) return 0; //map::iterator it; int cnt=0; - //it=clear_it; + it=clear_it; int size=mp.size(); int num_to_clean=size/conn_clear_ratio+conn_clear_min; //clear 1/10 each time,to avoid latency glitch @@ -301,43 +311,37 @@ int conn_manager_t::clear_inactive0() for(;;) { if(cnt>=num_to_clean) break; + if(mp.begin()==mp.end()) break; - if(lru.empty()) break; - address_t key; - my_time_t ts=lru.peek_back(key); - - //if(mp.begin()==mp.end()) break; - - //if(it==mp.end()) - //{ - // it=mp.begin(); - //} - - auto it=mp.find(key); + if(it==mp.end()) + { + it=mp.begin(); + } if(it->second->state.server_current_state==server_ready &¤t_time - it->second->last_hb_recv_time <=server_conn_timeout) { - //it++; + it++; } else if(it->second->state.server_current_state!=server_ready&& current_time - it->second->last_state_time <=server_handshake_timeout ) { - //it++; + it++; } else if(it->second->blob!=0&&it->second->blob->conv_manager.s.get_size() >0) { assert(it->second->state.server_current_state==server_ready); - //it++; + it++; } else { mylog(log_info,"[%s:%d]inactive conn cleared \n",my_ntoa(it->second->raw_info.recv_info.src_ip),it->second->raw_info.recv_info.src_port); - //old_it=it; - //it++; - erase(it); + old_it=it; + it++; + erase(old_it); } cnt++; } - //clear_it=it; + clear_it=it; + return 0; } diff --git a/connection.h b/connection.h index b5d1469..1716b23 100644 --- a/connection.h +++ b/connection.h @@ -283,9 +283,9 @@ struct conn_manager_t //manager for connections. for client,we dont need conn_m unordered_map mp; //put it at end so that it de-consturcts first - lru_collector_t lru; + //lru_collector_t lru; - //unordered_map::iterator clear_it; + unordered_map::iterator clear_it; long long last_clear_time; diff --git a/main.cpp b/main.cpp index d70e313..93f3686 100755 --- a/main.cpp +++ b/main.cpp @@ -591,7 +591,7 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,id_t tmp_oppsite_id ) return 0; }*/ int server_on_timer(conn_info_t &conn_info) //for server. called when a timer is ready in epoll.for server,there will be one timer for every connection - +// there is also a global timer for server,but its not handled here { char ip_port[40]; u32_t ip=conn_info.raw_info.send_info.dst_ip;