use unrestricted union instead of struct

This commit is contained in:
wangyu- 2018-07-28 03:42:00 -05:00
parent 0980d89072
commit 8ade602be1
3 changed files with 26 additions and 9 deletions

@ -48,7 +48,7 @@
#else
#include <linux/if_ether.h>
//#include <linux/if_ether.h>
#include <linux/filter.h>
#include <linux/if_packet.h>
#include <sys/epoll.h>

@ -131,12 +131,6 @@ conn_manager_t conn_manager;
{
assert(0==1);
//mylog(log_error,"called!!!!!!!!!!!!!\n");
*this=b;
if(blob!=0)
{
blob=new blob_t(*b.blob);
}
}
conn_info_t& conn_info_t::operator=(const conn_info_t& b)

@ -219,12 +219,35 @@ struct conv_manager_t // manage the udp connections
struct blob_t:not_copy_able_t //used in conn_info_t.
{
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 is here to avoid copying when a connection is recovered
{
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;
anti_replay_t anti_replay;//anti_replay_t is here bc its huge,its allocation is delayed.