mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
use unrestricted union instead of struct
This commit is contained in:
parent
0980d89072
commit
8ade602be1
2
common.h
2
common.h
@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <linux/if_ether.h>
|
//#include <linux/if_ether.h>
|
||||||
#include <linux/filter.h>
|
#include <linux/filter.h>
|
||||||
#include <linux/if_packet.h>
|
#include <linux/if_packet.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
|
@ -131,12 +131,6 @@ conn_manager_t conn_manager;
|
|||||||
{
|
{
|
||||||
assert(0==1);
|
assert(0==1);
|
||||||
//mylog(log_error,"called!!!!!!!!!!!!!\n");
|
//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)
|
conn_info_t& conn_info_t::operator=(const conn_info_t& b)
|
||||||
|
27
connection.h
27
connection.h
@ -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 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
|
union tmp_union_t//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.
|
|
||||||
{
|
{
|
||||||
conv_manager_t<address_t> c;
|
conv_manager_t<address_t> c;
|
||||||
conv_manager_t<u64_t> s;
|
conv_manager_t<u64_t> s;
|
||||||
//avoid templates here and there, avoid pointer and type cast
|
//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;
|
}conv_manager;
|
||||||
|
|
||||||
anti_replay_t anti_replay;//anti_replay_t is here bc its huge,its allocation is delayed.
|
anti_replay_t anti_replay;//anti_replay_t is here bc its huge,its allocation is delayed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user