mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-01-18 22:09:35 +08:00
changed struct to c++11 unresticted union
This commit is contained in:
parent
7e8d02dac1
commit
513bed7382
@ -21,7 +21,7 @@ unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"},
|
||||
char iptables_rule[200]="";
|
||||
//int is_client = 0, is_server = 0;
|
||||
|
||||
program_mode_t client_or_server=unset_mode;//0 unset; 1client 2server
|
||||
program_mode_t program_mode=unset_mode;//0 unset; 1client 2server
|
||||
|
||||
working_mode_t working_mode=tunnel_mode;
|
||||
|
||||
|
2
common.h
2
common.h
@ -152,7 +152,7 @@ extern int about_to_exit;
|
||||
enum raw_mode_t{mode_faketcp=0,mode_udp,mode_icmp,mode_end};
|
||||
extern raw_mode_t raw_mode;
|
||||
enum program_mode_t {unset_mode=0,client_mode,server_mode};
|
||||
extern program_mode_t client_or_server;
|
||||
extern program_mode_t program_mode;
|
||||
extern unordered_map<int, const char*> raw_mode_tostring ;
|
||||
|
||||
enum working_mode_t {unset_working_mode=0,tunnel_mode,tun_dev_mode};
|
||||
|
28
connection.h
28
connection.h
@ -255,14 +255,38 @@ struct stat_t
|
||||
struct conn_info_t //stores info for a raw connection.for client ,there is only one connection,for server there can be thousand of connection since server can
|
||||
//handle multiple clients
|
||||
{
|
||||
struct //conv_manager_t is here to avoid copying when a connection is recovered
|
||||
//TODO maybe an unconstrained union is better, but struct is okay since conv_manger is small when no data is filled in.
|
||||
union tmp_union_t
|
||||
{
|
||||
conv_manager_t<address_t> c;
|
||||
conv_manager_t<u64_t> s;
|
||||
//avoid templates here and there, avoid pointer and type cast
|
||||
tmp_union_t()
|
||||
{
|
||||
if(program_mode==client_mode)
|
||||
{
|
||||
new( &c ) conv_manager_t<address_t>();
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(program_mode==server_mode);
|
||||
new( &s ) conv_manager_t<u64_t>();
|
||||
}
|
||||
}
|
||||
~tmp_union_t()
|
||||
{
|
||||
if(program_mode==client_mode)
|
||||
{
|
||||
c.~conv_manager_t<address_t>();
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(program_mode==server_mode);
|
||||
s.~conv_manager_t<u64_t>();
|
||||
}
|
||||
}
|
||||
}conv_manager;
|
||||
|
||||
|
||||
fec_encode_manager_t fec_encode_manager;
|
||||
fec_decode_manager_t fec_decode_manager;
|
||||
ev_timer timer;
|
||||
|
2
main.cpp
2
main.cpp
@ -153,7 +153,7 @@ int main(int argc, char *argv[])
|
||||
sprintf(tun_dev,"tun%u",get_fake_random_number()%1000);
|
||||
}
|
||||
|
||||
if(client_or_server==client_mode)
|
||||
if(program_mode==client_mode)
|
||||
{
|
||||
tunnel_client_event_loop();
|
||||
}
|
||||
|
8
misc.cpp
8
misc.cpp
@ -965,11 +965,11 @@ void process_arg(int argc, char *argv[])
|
||||
}
|
||||
if(is_client==1)
|
||||
{
|
||||
client_or_server=client_mode;
|
||||
program_mode=client_mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
client_or_server=server_mode;
|
||||
program_mode=server_mode;
|
||||
}
|
||||
|
||||
|
||||
@ -984,12 +984,12 @@ void process_arg(int argc, char *argv[])
|
||||
}
|
||||
else if(working_mode==tun_dev_mode)
|
||||
{
|
||||
if(client_or_server==client_mode&&no_r)
|
||||
if(program_mode==client_mode&&no_r)
|
||||
{
|
||||
mylog(log_fatal,"error: -r not found\n");
|
||||
myexit(-1);
|
||||
}
|
||||
else if(client_or_server==server_mode&&no_l)
|
||||
else if(program_mode==server_mode&&no_l)
|
||||
{
|
||||
mylog(log_fatal,"error: -l not found\n");
|
||||
myexit(-1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user