In "RunController.h":
/*
Modify in 2012_04_07:
@1: modify the ~RunController(), in which MNs can be destruct without any obstruct, and guide MNs to destroy their pkts in buffer.
*/
In "Node.h":
/*
Modify in 2012_04_07:
@1: modify the Clear_MNs_Pkts(), and add the DestroyPkts() function into it;
@2: modify the ReceiveAndStorePkt( int nPktType, char* pPkt), every MN should keep its own pkts buffer, not the pointer to the source MN's newed pkt.
*/
Display the modified ReceiveAndStorePkt function here:
// ---------------- ReceiveAndStorePkt:
// Create a new Packet depend on the pSrcPkt, and store it into its buffer Storage.
void MNode::ReceiveAndStorePkt( _in int nPktType, _in char* pSrcPkt)
{
assert( NULL != pSrcPkt);
if ( NULL == pSrcPkt)
{
LogFile::instance()->m_ofErrLog << "Error: in MNode::StorePkt, NULL == pSrcPkt.\n";
return;
}
// 1) Copy and Store the received Pkt, !! must create a new pPkt_dataPiece here.
char* pPktData = new char[PIECESIZE+1];
memset( pPktData, 0, PIECESIZE+1 );
memcpy( pPktData, pSrcPkt, PIECESIZE );
this->m_map_PktID__PktType_pData.insert( make_pair(m_nPktID, make_pair( nPktType, pPktData )) );
m_nPktID++; // every time, the PktID++.
// ...
}
// ------------- ReceiveAndStorePkt:~
本文介绍了在特定网络仿真环境中,如何优化节点内的包管理和存储机制。主要包括修改了RunController类的析构函数以确保中间节点(MN)可以安全地销毁其缓冲区中的包,并更新了MNode类的ReceiveAndStorePkt函数,确保每个MN维护自己的包缓冲区而非指向源MN中新建包的指针。
1万+

被折叠的 条评论
为什么被折叠?



