Skip to content

Commit

Permalink
before change to multiplex
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Sep 23, 2017
1 parent da48f6e commit 45032e4
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 197 deletions.
3 changes: 2 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const u32_t conv_clear_interval=200;
const u32_t timer_interval=400;
const int conv_clear_ratio=40;
const int conv_clear_min=5;
const u32_t conv_timeout=20000;
////const u32_t conv_timeout=180000;
const u32_t conv_timeout=40000;//for test
const int max_conv_num=10000;

/*
Expand Down
31 changes: 16 additions & 15 deletions conn_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@

int disable_conv_clear=0;

conn_manager_t::conn_manager_t() {
conn_manager_t_not_used::conn_manager_t_not_used() {
clear_it = fd_last_active_time.begin();
long long last_clear_time = 0;
rehash();
//clear_function=0;
}
conn_manager_t::~conn_manager_t() {
conn_manager_t_not_used::~conn_manager_t_not_used() {
clear();
}
int conn_manager_t::get_size() {
int conn_manager_t_not_used::get_size() {
return fd_to_u64.size();
}
void conn_manager_t::rehash() {
void conn_manager_t_not_used::rehash() {
u64_to_fd.rehash(10007);
fd_to_u64.rehash(10007);
fd_last_active_time.rehash(10007);
}
void conn_manager_t::clear() {
void conn_manager_t_not_used::clear() {
if (disable_conv_clear)
return;

Expand All @@ -41,28 +41,28 @@ void conn_manager_t::clear() {
clear_it = fd_last_active_time.begin();

}
int conn_manager_t::exist_fd(u32_t fd) {
int conn_manager_t_not_used::exist_fd(u32_t fd) {
return fd_to_u64.find(fd) != fd_to_u64.end();
}
int conn_manager_t::exist_u64(u64_t u64) {
int conn_manager_t_not_used::exist_u64(u64_t u64) {
return u64_to_fd.find(u64) != u64_to_fd.end();
}
u32_t conn_manager_t::find_fd_by_u64(u64_t u64) {
u32_t conn_manager_t_not_used::find_fd_by_u64(u64_t u64) {
return u64_to_fd[u64];
}
u64_t conn_manager_t::find_u64_by_fd(u32_t fd) {
u64_t conn_manager_t_not_used::find_u64_by_fd(u32_t fd) {
return fd_to_u64[fd];
}
int conn_manager_t::update_active_time(u32_t fd) {
int conn_manager_t_not_used::update_active_time(u32_t fd) {
return fd_last_active_time[fd] = get_current_time();
}
int conn_manager_t::insert_fd(u32_t fd, u64_t u64) {
int conn_manager_t_not_used::insert_fd(u32_t fd, u64_t u64) {
u64_to_fd[u64] = fd;
fd_to_u64[fd] = u64;
fd_last_active_time[fd] = get_current_time();
return 0;
}
int conn_manager_t::erase_fd(u32_t fd) {
int conn_manager_t_not_used::erase_fd(u32_t fd) {
if (disable_conv_clear)
return 0;
u64_t u64 = fd_to_u64[fd];
Expand All @@ -81,21 +81,22 @@ int conn_manager_t::erase_fd(u32_t fd) {
fd_last_active_time.erase(fd);
return 0;
}
/*
void conn_manager_t::check_clear_list() {
while (!clear_list.empty()) {
int fd = *clear_list.begin();
clear_list.pop_front();
erase_fd(fd);
}
}
int conn_manager_t::clear_inactive() {
}*/
int conn_manager_t_not_used::clear_inactive() {
if (get_current_time() - last_clear_time > conv_clear_interval) {
last_clear_time = get_current_time();
return clear_inactive0();
}
return 0;
}
int conn_manager_t::clear_inactive0() {
int conn_manager_t_not_used::clear_inactive0() {
if (disable_conv_clear)
return 0;

Expand Down
10 changes: 5 additions & 5 deletions conn_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

extern int disable_conv_clear;

struct conn_manager_t //TODO change map to unordered map
struct conn_manager_t_not_used //TODO change map to unordered map
{
//typedef hash_map map;
unordered_map<u64_t,u32_t> u64_to_fd; //conv and u64 are both supposed to be uniq
Expand All @@ -29,9 +29,9 @@ struct conn_manager_t //TODO change map to unordered map
//void (*clear_function)(uint64_t u64) ;

long long last_clear_time;
list<int> clear_list;
conn_manager_t();
~conn_manager_t();
//list<int> clear_list;
conn_manager_t_not_used();
~conn_manager_t_not_used();
int get_size();
void rehash();
void clear();
Expand All @@ -42,7 +42,7 @@ struct conn_manager_t //TODO change map to unordered map
int update_active_time(u32_t fd);
int insert_fd(u32_t fd,u64_t u64);
int erase_fd(u32_t fd);
void check_clear_list();
//void check_clear_list();
int clear_inactive();
int clear_inactive0();

Expand Down
Loading

0 comments on commit 45032e4

Please sign in to comment.