网络地址等基础类增加赋值函数,支持直接赋值拷贝

This commit is contained in:
大石头X2 2017-02-06 09:51:54 +08:00
parent 1014c0a3b7
commit 84bfeb50d7
8 changed files with 29 additions and 4 deletions

View File

@ -106,6 +106,13 @@ IPAddress& IPAddress::operator=(const Buffer& arr)
return *this;
}
IPAddress& IPAddress::operator=(const IPAddress& addr)
{
Value = addr.Value;
return *this;
}
// 重载索引运算符[],让它可以像数组一样使用下标索引。
byte& IPAddress::operator[](int i)
{

View File

@ -30,6 +30,7 @@ public:
IPAddress& operator=(uint v) { Value = v; return *this; }
IPAddress& operator=(const byte* v);
IPAddress& operator=(const Buffer& arr);
IPAddress& operator=(const IPAddress& addr);
// 重载索引运算符[],让它可以像数组一样使用下标索引。
byte& operator[](int i);

View File

@ -40,6 +40,14 @@ IPEndPoint& IPEndPoint::operator=(const Buffer& arr)
return *this;
}
IPEndPoint& IPEndPoint::operator=(const IPEndPoint& endPoint)
{
Address = endPoint.Address;
Port = endPoint.Port;
return *this;
}
// 字节数组
ByteArray IPEndPoint::ToArray() const
{

View File

@ -15,6 +15,7 @@ public:
IPEndPoint(const Buffer& arr);
IPEndPoint& operator=(const Buffer& arr);
IPEndPoint& operator=(const IPEndPoint& endPoint);
// 字节数组
ByteArray ToArray() const;

View File

@ -74,6 +74,13 @@ MacAddress& MacAddress::operator=(const Buffer& arr)
return *this;
}
MacAddress& MacAddress::operator=(const MacAddress& mac)
{
Value = mac.Value;
return *this;
}
// 重载索引运算符[],让它可以像数组一样使用下标索引。
byte& MacAddress::operator[](int i)
{

View File

@ -20,6 +20,7 @@ public:
MacAddress& operator=(UInt64 v);
MacAddress& operator=(const byte* buf);
MacAddress& operator=(const Buffer& arr);
MacAddress& operator=(const MacAddress& mac);
// 重载索引运算符[],让它可以像数组一样使用下标索引。
byte& operator[](int i);

View File

@ -382,8 +382,8 @@ void TokenClient::SayHello(bool broadcast)
{
auto ctrl = cs[0];
auto sock = ctrl->Socket;
ext.EndPoint.Address = sock->Host->IP;
ext.EndPoint.Port = sock->Local.Port;
//ext.EndPoint.Address = sock->Local.Address;
ext.EndPoint = sock->Local;
ext.Protocol = sock->Protocol == NetType::Udp ? 17 : 6;
}

View File

@ -178,8 +178,8 @@ bool TokenSession::OnHello(TokenMessage& msg)
ext2.Key = key;
auto sock = Control.Socket;
ext2.EndPoint.Address = sock->Host->IP;
ext2.EndPoint.Port = sock->Local.Port;
//ext2.EndPoint.Address = sock->Host->IP;
ext2.EndPoint = sock->Local;
ext2.Cipher = "RC4";
ext2.Name = Client.Cfg->User();