just commit

This commit is contained in:
wangyu- 2017-09-27 01:23:08 -05:00
parent 3790eaf67e
commit bf121f6f73
4 changed files with 14 additions and 26 deletions

View File

@ -15,13 +15,18 @@ const int disable_conn_clear=0;//a raw connection is called conn.
conn_manager_t conn_manager;
void server_clear_function(u64_t u64);
void server_clear_function(u64_t u64)//used in conv_manager in server mode.for server we have to use one udp fd for one conv(udp connection),
//so we have to close the fd when conv expires
{
int fd64=u64;
assert(fd_manager.exist(fd64));
fd_manager.close(fd64);
}
conv_manager_t::conv_manager_t()
{
clear_it=conv_last_active_time.begin();
long long last_clear_time=0;
//clear_function=0;
}
conv_manager_t::~conv_manager_t()
{
@ -85,7 +90,7 @@ conv_manager_t::~conv_manager_t()
{
return conv_last_active_time[conv]=get_current_time();
}
int conv_manager_t::insert_conv(u32_t conv,u64_t u64)
int conv_manager_t::insert_conv(u32_t conv,u64_t u64)//////todo add capacity
{
u64_to_conv[u64]=conv;
conv_to_u64[conv]=u64;
@ -118,7 +123,6 @@ conv_manager_t::~conv_manager_t()
{
if(disable_conv_clear) return 0;
//map<uint32_t,uint64_t>::iterator it;
int cnt=0;
it=clear_it;
@ -189,7 +193,8 @@ conv_manager_t::~conv_manager_t()
mp[u64];
return 0;
}*/
conn_info_t *& conn_manager_t::find_insert_p(ip_port_t ip_port) //be aware,the adress may change after rehash
conn_info_t *& conn_manager_t::find_insert_p(ip_port_t ip_port) //todo capacity
//be aware,the adress may change after rehash
{
u64_t u64=ip_port.to_u64();
unordered_map<u64_t,conn_info_t*>::iterator it=mp.find(u64);
@ -305,14 +310,3 @@ int conn_manager_t::clear_inactive0()
return 0;
}
void server_clear_function(u64_t u64)//used in conv_manager in server mode.for server we have to use one udp fd for one conv(udp connection),
//so we have to close the fd when conv expires
{
int fd64=u64;
int ret;
assert(fd_manager.exist(fd64));
int fd=fd_manager.to_fd(fd64);
fd_manager.close(fd64);
}

View File

@ -36,11 +36,9 @@ struct conv_manager_t // manage the udp connections
//typedef hash_map map;
unordered_map<u64_t,u32_t> u64_to_conv; //conv and u64 are both supposed to be uniq
unordered_map<u32_t,u64_t> conv_to_u64;
unordered_map<u32_t,u64_t> conv_last_active_time;
unordered_map<u32_t,u64_t>::iterator clear_it;
unordered_map<u32_t,u64_t>::iterator it;
unordered_map<u32_t,u64_t>::iterator old_it;

View File

@ -14,7 +14,7 @@
struct fd_manager_t //conver fd to a uniq 64bit number,avoid fd value conflict caused by close and re-create
//not used currently
//this class is not strictly necessary,it just makes epoll fd handling easier
{
fd_info_t & get_info(fd64_t fd64);
int exist_info(fd64_t);

View File

@ -210,13 +210,14 @@ int client_event_loop()
dest.conv=conv;
my_send(dest,data,data_len);
}
else if (events[idx].data.u64 == remote_fd64)
else if(events[idx].data.u64>u32_t(-1) )
{
char data[buf_len];
if(!fd_manager.exist(remote_fd64)) //fd64 has been closed
if(!fd_manager.exist(events[idx].data.u64)) //fd64 has been closed
{
continue;
}
assert(events[idx].data.u64==remote_fd64);
int fd=fd_manager.to_fd(remote_fd64);
int data_len =recv(fd,data,max_data_len,0);
mylog(log_trace, "received data from udp fd %d, len=%d\n", remote_fd,data_len);
@ -258,11 +259,6 @@ int client_event_loop()
mylog(log_trace,"epoll_trigger_counter: %d \n",epoll_trigger_counter);
epoll_trigger_counter=0;
}*/
else if(events[idx].data.u64>u32_t(-1) )
{
assert(!fd_manager.exist(events[idx].data.u64));//this fd64 has been closed
}
else
{
mylog(log_fatal,"unknown fd,this should never happen\n");