Skip to content

Commit

Permalink
just commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Sep 27, 2017
1 parent bf121f6 commit a71576c
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 56 deletions.
2 changes: 1 addition & 1 deletion common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ char iptables_rule[200]="";

program_mode_t program_mode=unset_mode;//0 unset; 1client 2server

u64_t get_current_time()
u64_t get_current_time()//ms
{
timespec tmp_time;
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
Expand Down
35 changes: 21 additions & 14 deletions connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ conv_manager_t::~conv_manager_t()
}
int conv_manager_t::insert_conv(u32_t conv,u64_t u64)//////todo add capacity
{
int bucket_size_before=conv_last_active_time.bucket_count();
u64_to_conv[u64]=conv;
conv_to_u64[conv]=u64;
conv_last_active_time[conv]=get_current_time();
int bucket_size_after=conv_last_active_time.bucket_count();
if(bucket_size_after!=bucket_size_before)
clear_it=conv_last_active_time.begin();
return 0;
}
int conv_manager_t::erase_conv(u32_t conv)
Expand Down Expand Up @@ -168,13 +172,13 @@ conv_manager_t::~conv_manager_t()
}
conn_manager_t::conn_manager_t()
{
ready_num=0;
//ready_num=0;
mp.reserve(100007);
//fd64_mp.reserve(100007);
clear_it=mp.begin();
last_clear_time=0;
}
int conn_manager_t::exist_ip_port(ip_port_t ip_port)
int conn_manager_t::exist(ip_port_t ip_port)
{
u64_t u64=ip_port.to_u64();
if(mp.find(u64)!=mp.end())
Expand All @@ -193,27 +197,30 @@ conv_manager_t::~conv_manager_t()
mp[u64];
return 0;
}*/
conn_info_t *& conn_manager_t::find_insert_p(ip_port_t ip_port) //todo capacity

conn_info_t *& conn_manager_t::find_p(ip_port_t ip_port) //todo capacity
//be aware,the adress may change after rehash
{
assert(exist(ip_port));
u64_t u64=ip_port.to_u64();
unordered_map<u64_t,conn_info_t*>::iterator it=mp.find(u64);
if(it==mp.end())
{
mp[u64]=new conn_info_t;
}
return mp[u64];
}
conn_info_t & conn_manager_t::find_insert(ip_port_t ip_port) //be aware,the adress may change after rehash
conn_info_t & conn_manager_t::find(ip_port_t ip_port) //be aware,the adress may change after rehash
{
assert(exist(ip_port));
u64_t u64=ip_port.to_u64();
unordered_map<u64_t,conn_info_t*>::iterator it=mp.find(u64);
if(it==mp.end())
{
mp[u64]=new conn_info_t;
}
return *mp[u64];
}
int conn_manager_t::insert(ip_port_t ip_port)
{
assert(!exist(ip_port));
int bucket_size_before=mp.bucket_count();
mp[ip_port.to_u64()]=new conn_info_t;
int bucket_size_after=mp.bucket_count();
if(bucket_size_after!=bucket_size_before)
clear_it=mp.begin();
return 0;
}
/*
int conn_manager_t::exist_fd64(fd64_t fd64)
{
Expand Down
16 changes: 5 additions & 11 deletions connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,21 @@ struct conn_info_t //stores info for a raw connection.for client ,there is o
struct conn_manager_t //manager for connections. for client,we dont need conn_manager since there is only one connection.for server we use one conn_manager for all connections
{

u32_t ready_num;

// unordered_map<fd64_t,u64_t> fd64_mp;
unordered_map<u64_t,conn_info_t*> mp;//<ip,port> to conn_info_t;
//put it at end so that it de-consturcts first

unordered_map<u64_t,conn_info_t*>::iterator clear_it;

long long last_clear_time;

conn_manager_t();
int exist_ip_port(ip_port_t);
conn_info_t *& find_insert_p(ip_port_t); //be aware,the adress may change after rehash
conn_info_t & find_insert(ip_port_t) ; //be aware,the adress may change after rehash
int exist(ip_port_t);
conn_info_t *& find_p(ip_port_t); //be aware,the adress may change after rehash
conn_info_t & find(ip_port_t) ; //be aware,the adress may change after rehash
int insert(ip_port_t);
/*
int exist_fd64(fd64_t fd64);
void insert_fd64(fd64_t fd64,ip_port_t);
ip_port_t find_by_fd64(fd64_t fd64);*/


int erase(unordered_map<u64_t,conn_info_t*>::iterator erase_it);
int erase(unordered_map<u64_t,conn_info_t*>::iterator erase_it);
int clear_inactive();
int clear_inactive0();

Expand Down
15 changes: 10 additions & 5 deletions delay_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ delay_manager_t::~delay_manager_t()
{
//TODO ,we currently dont need to deconstruct it
}
/*

int delay_manager_t::get_timer_fd()
{
return delay_timer_fd;
}*/

int delay_manager_t::add(my_time_t delay,delay_data_t &delay_data)
return timer_fd;
}
//int add(my_time_t delay,const dest_t &dest,const char *data,int len);
int delay_manager_t::add(my_time_t delay,const dest_t &dest,char *data,int len)
{
delay_data_t delay_data;
delay_data.dest=dest;
delay_data.data=data;
delay_data.len=len;

if(capacity!=0&&int(delay_mp.size()) >=capacity)
{
mylog(log_warn,"max pending packet reached,ignored\n");
Expand Down
4 changes: 2 additions & 2 deletions delay_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ struct delay_manager_t
multimap<my_time_t,delay_data_t> delay_mp; //unit us,1 us=0.001ms
delay_manager_t();
~delay_manager_t();
//int get_timer_fd();
int get_timer_fd();
int check();
int add(my_time_t delay,delay_data_t &delay_data);
int add(my_time_t delay,const dest_t &dest,char *data,int len);
};

#endif /* DELAY_MANAGER_H_ */
11 changes: 5 additions & 6 deletions fd_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ void fd_manager_t::close(fd64_t fd64)
close(fd);
//return 0;
}
void fd_manager_t::reserve()
void fd_manager_t::reserve(int n)
{
fd_to_fd64_mp.reserve(10007);
fd64_to_fd_mp.reserve(10007);
fd_info_mp.reserve(10007);
//return 0;
fd_to_fd64_mp.reserve(n);
fd64_to_fd_mp.reserve(n);
fd_info_mp.reserve(n);
}
u64_t fd_manager_t::create(int fd)
{
Expand All @@ -67,7 +66,7 @@ u64_t fd_manager_t::create(int fd)
fd_manager_t::fd_manager_t()
{
counter=u32_t(-1);
counter+=2;
counter+=10;
}
fd_info_t & fd_manager_t::get_info(fd64_t fd64)
{
Expand Down
2 changes: 1 addition & 1 deletion fd_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct fd_manager_t //conver fd to a uniq 64bit number,avoid fd value conflict
int exist(fd64_t fd64);
int to_fd(fd64_t);
void close(fd64_t fd64);
void reserve();
void reserve(int n);
u64_t create(int fd);
fd_manager_t();
private:
Expand Down
28 changes: 28 additions & 0 deletions lib/rs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Author: root
*/
#include "rs.h"
#include "stdlib.h"
#include "string.h"

void rs_encode(void *code,char *data[],int size)
{
Expand Down Expand Up @@ -42,3 +44,29 @@ int rs_decode(void *code,char *data[],int size)
}
return fec_decode(code,(void**)data,index,size);
}

static void * (*table)[256]=0;
void* get_code(int k,int n)
{
if (table==0)
{
table=(void* (*)[256]) malloc(sizeof(void*)*256*256);
memset(table,0,sizeof(void*)*256*256);
}
if(table[k][n]==0)
{
table[k][n]=fec_new(k,n);
}
return table[k][n];
}
void rs_encode2(int k,int n,char *data[],int size)
{
void* code=get_code(k,n);
rs_encode(code,data,size);
}

int rs_decode2(int k,int n,char *data[],int size)
{
void* code=get_code(k,n);
return rs_decode(code,data,size);
}
4 changes: 4 additions & 0 deletions lib/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void rs_encode(void *code,char *data[],int size);
int rs_decode(void *code,char *data[],int size);


void rs_encode2(int k,int n,char *data[],int size);

int rs_decode2(int k,int n,char *data[],int size);




Expand Down
Loading

0 comments on commit a71576c

Please sign in to comment.