Record of NS_Simulator bug fixed.

本文介绍了在特定网络仿真环境中,如何优化节点内的包管理和存储机制。主要包括修改了RunController类的析构函数以确保中间节点(MN)可以安全地销毁其缓冲区中的包,并更新了MNode类的ReceiveAndStorePkt函数,确保每个MN维护自己的包缓冲区而非指向源MN中新建包的指针。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   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:~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值