mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-11-26 22:55:37 +08:00
changed struct to c++11 unresticted union
This commit is contained in:
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;
|
||||
|
||||
Reference in New Issue
Block a user