changed struct to c++11 unresticted union

This commit is contained in:
wangyu-
2018-07-28 03:48:57 -05:00
parent 7e8d02dac1
commit 513bed7382
5 changed files with 33 additions and 9 deletions

View File

@@ -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;