当前位置: 首页>>代码示例>>C++>>正文


C++ PacketHdr::getIntegerInfo方法代码示例

本文整理汇总了C++中PacketHdr::getIntegerInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketHdr::getIntegerInfo方法的具体用法?C++ PacketHdr::getIntegerInfo怎么用?C++ PacketHdr::getIntegerInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PacketHdr的用法示例。


在下文中一共展示了PacketHdr::getIntegerInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void *interface4(void *arg){
	printf("Starting interface4 thread\n");
	struct cShared *sh = (struct cShared *)arg;
	cout<<"This is interface4!"<<endl;

	Packet *recvPacket;
	PacketHdr *hdr;

	char type;
	int cid;
	int hid;
	int hopnum;
	int interface;

	while(1){
		// sleep(0.4);
		recvPacket = sh->recv_port4->receivePacket();
		if(recvPacket!=NULL){
            
		hdr = recvPacket->accessHeader();
		type = hdr->getOctet(0);


		//receive update packet: [type+cid+#hops]
		if(type==(char)0X02){
			int k=0;

			struct routing_Table *temp=new routing_Table;
			struct routing_Table *ptr=NULL;
			cid=hdr->getIntegerInfo(1);
			hopnum=hdr->getIntegerInfo(5);
			temp->CID=cid;
			temp->interf=4;
			temp->hopNum=hopnum;
			temp->nextrow=NULL;
			temp->previous=NULL;
			// updated in 0903 start
			// time_t t=time(0);
			int t=0;
			// updated in 0903 end
			temp->TtoE=t+TTL;

			ptr=sh->rtable;

			//update the routing table
				while(ptr!=NULL){
					if(ptr->CID==temp->CID){
						k=1;
						if(ptr->hopNum >= temp->hopNum){

							ptr->interf=4;
							ptr->hopNum=temp->hopNum;
							ptr->TtoE=temp->TtoE;

							//broadcast updated packet
							hdr->setIntegerInfo(hopnum+1,5);
							sh->send_port2->sendPacket(recvPacket);
							sh->send_port3->sendPacket(recvPacket);
							sh->send_port1->sendPacket(recvPacket);
						}
						else if(ptr->hopNum==temp->hopNum&&ptr->interf==temp->interf){
							ptr->TtoE=temp->TtoE;
						}

					}
						ptr=ptr->nextrow;
				}
				if(k==0){
					temp->nextrow=sh->rtable;
					sh->rtable->previous=temp;
					sh->rtable=temp;

					//broadcast updated packet
					hdr->setIntegerInfo(hopnum+1,5);
					sh->send_port2->sendPacket(recvPacket);
					sh->send_port3->sendPacket(recvPacket);
					sh->send_port1->sendPacket(recvPacket);
				}
			//}
			//delete ptr;

		}
		//receive response packet: [type+cid+hid+payload]
		else if(type==(char)0x01){
			int k=0;
			struct pending_Table *ptr=NULL;
			ptr=sh->ptable;
			cid=hdr->getIntegerInfo(1);
			hid=hdr->getIntegerInfo(5);
			//find the path in pending table
			while(ptr!=NULL){
				if(ptr->rCID==cid && ptr->HID==hid){
					interface=ptr->interf;
					k=1;
					//decided which interface should send the packet
					switch(interface){
						case 1:
							sh->send_port1->sendPacket(recvPacket);
							break;
						case 2:
//.........这里部分代码省略.........
开发者ID:YaoWang9287,项目名称:Files-sharing-network,代码行数:101,代码来源:Router.cpp


注:本文中的PacketHdr::getIntegerInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。