完全废弃TArray

This commit is contained in:
Stone 2016-06-04 04:03:49 +00:00
parent bcc060924d
commit a04264683c
4 changed files with 8 additions and 73 deletions

View File

@ -92,7 +92,7 @@ protected:
1 1
2 2
*/ */
template<typename T, int ArraySize = 0x40> /*template<typename T, int ArraySize = 0x40>
class TArray : public Array class TArray : public Array
{ {
protected: protected:
@ -204,6 +204,6 @@ public:
T* buf = (T*)_Arr; T* buf = (T*)_Arr;
return buf[i]; return buf[i];
} }
}; };*/
#endif #endif

View File

@ -7,7 +7,7 @@
1 Buffer => Object 1 Buffer => Object
2 Array => Buffer 2 Array => Buffer
3 ByteArray/String/TArray<T> => Array 3 ByteArray/String => Array
1 1

View File

@ -8,6 +8,7 @@
#define NET_DEBUG DEBUG #define NET_DEBUG DEBUG
/******************************** TinyIP ********************************/
TinyIP::TinyIP() : _Arr(0) { Init(); } TinyIP::TinyIP() : _Arr(0) { Init(); }
TinyIP::TinyIP(ITransport* port) : _Arr(0) TinyIP::TinyIP(ITransport* port) : _Arr(0)
@ -36,7 +37,6 @@ void TinyIP::Init()
Mask = 0x00FFFFFF; Mask = 0x00FFFFFF;
DHCPServer = Gateway = DNSServer = IP = 0; DHCPServer = Gateway = DNSServer = IP = 0;
//Sockets.SetCapacity(0x10);
Arp = nullptr; Arp = nullptr;
} }
@ -148,10 +148,9 @@ void TinyIP::Process(Stream& ms)
// 各处理器有可能改变数据流游标,这里备份一下 // 各处理器有可能改变数据流游标,这里备份一下
uint p = ms.Position(); uint p = ms.Position();
// 考虑到可能有通用端口处理器,也可能有专用端口处理器(一般在后面),这里偷懒使用倒序处理 // 考虑到可能有通用端口处理器,也可能有专用端口处理器(一般在后面),这里偷懒使用倒序处理
uint count = Sockets.Length(); for(int i=Sockets.Count()-1; i>=0; i--)
for(int i=count-1; i>=0; i--)
{ {
TinySocket* socket = Sockets[i]; auto socket = (TinySocket*)Sockets[i];
if(socket && socket->Enable) if(socket && socket->Enable)
{ {
// 必须类型匹配 // 必须类型匹配
@ -395,6 +394,7 @@ bool TinyIP::IsBroadcast(const IPAddress& ip)
} }
#endif #endif
/******************************** TinySocket ********************************/
TinySocket::TinySocket(TinyIP* tip, IP_TYPE type) TinySocket::TinySocket(TinyIP* tip, IP_TYPE type)
{ {
assert(tip, "空的Tip"); assert(tip, "空的Tip");
@ -405,19 +405,6 @@ TinySocket::TinySocket(TinyIP* tip, IP_TYPE type)
// 除了ARP以外加入到列表 // 除了ARP以外加入到列表
if(type != IP_NONE) tip->Sockets.Add(this); if(type != IP_NONE) tip->Sockets.Add(this);
/*if(type != IP_NONE)
{
for(int i=0; i<tip->Sockets.Length(); i++)
{
if(tip->Sockets[i] == nullptr)
{
tip->Sockets[i] = this;
break;
}
}
}*/
//int idx = tip->Sockets.FindIndex(nullptr);
//if(idx >= 0) tip->Sockets[idx] = this;
} }
TinySocket::~TinySocket() TinySocket::~TinySocket()
@ -427,44 +414,4 @@ TinySocket::~TinySocket()
Enable = false; Enable = false;
// 从TinyIP中删除当前Socket // 从TinyIP中删除当前Socket
Tip->Sockets.Remove(this); Tip->Sockets.Remove(this);
/*for(int i=0; i<Tip->Sockets.Length(); i++)
{
if(Tip->Sockets[i] == this)
{
Tip->Sockets[i] = nullptr;
break;
}
}*/
//int idx = Tip->Sockets.FindIndex(this);
//if(idx >= 0) Tip->Sockets[idx] = nullptr;
} }
TinySocket* SocketList::FindByType(ushort type)
{
for(int i=Length()-1; i>=0; i--)
{
TinySocket* socket = (*this)[i];
if(socket)
{
// 必须类型匹配
if(socket->Type == type) return socket;
}
}
return nullptr;
}
void SocketList::Add(const TinySocket* socket)
{
int idx = FindIndex(nullptr);
// 如果找不到空位,则加在最后
if(idx < 0) idx = Length();
SetAt(idx, (TinySocket*)socket);
}
void SocketList::Remove(const TinySocket* socket)
{
int idx = FindIndex((TinySocket*)socket);
if(idx >= 0) (*this)[idx] = nullptr;
}

View File

@ -25,18 +25,6 @@ public:
virtual bool Process(IP_HEADER& ip, Stream& ms) = 0; virtual bool Process(IP_HEADER& ip, Stream& ms) = 0;
}; };
// Socket列表
class SocketList : public TArray<TinySocket*>
{
public:
TinySocket* FindByType(ushort type);
void Add(const TinySocket* socket);
void Remove(const TinySocket* socket);
private:
List _Sockets;
};
// 精简以太网协议。封装以太网帧以及IP协议不包含其它协议实现仅提供底层支持。 // 精简以太网协议。封装以太网帧以及IP协议不包含其它协议实现仅提供底层支持。
class TinyIP : public Object, public ISocketHost class TinyIP : public Object, public ISocketHost
{ {
@ -63,7 +51,7 @@ public:
// Arp套接字 // Arp套接字
TinySocket* Arp; TinySocket* Arp;
// 套接字列表。套接字根据类型来识别 // 套接字列表。套接字根据类型来识别
SocketList Sockets; List Sockets;
TinyIP(); TinyIP();
TinyIP(ITransport* port); TinyIP(ITransport* port);