⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket_receive_protocol_handler.cpp

📁 程序实现了在ip协议之上加一层RUDP协议
💻 CPP
字号:
// SOCKET_Receive_Protocol_Handler.cpp: implementation of the SOCKET_Receive_Protocol_Handler class.
//
//////////////////////////////////////////////////////////////////////

#include "SOCKET_Receive_Protocol_Handler.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SOCKET_Receive_Protocol_Handler* SOCKET_Receive_Protocol_Handler::pinstance = NULL;// 初始化指针


/*
	initial, make sure the relate module get the single object
*/
SOCKET_Receive_Protocol_Handler::SOCKET_Receive_Protocol_Handler()
{
	activity_list_manager_ptr=SOCKET_ACTIVITY_LIST_Handler::get_instance();
	rudp_enunpacket_manager_ptr=RUDP_EnUnPacket_Handler::get_instance();
	retransmit_timing2_ptr=SOCKET_ReTransmit_Timing2_Protocol_Handler::get_instance();
	socket_sr_ptr=Socket_SR::get_instance();
	sequence_manager_ptr=SOCKET_Sequence_Manager::get_instance();
	control_manager_pter=SOCKET_Control_Protocol_Handler::get_instance();
}

SOCKET_Receive_Protocol_Handler::~SOCKET_Receive_Protocol_Handler()
{
	
}


/*
  factory pattern, make sure there is only one object of this class
*/
SOCKET_Receive_Protocol_Handler* SOCKET_Receive_Protocol_Handler::get_instance ()
{
	if (pinstance == NULL)
	{
		pinstance = new SOCKET_Receive_Protocol_Handler;
	}
	return pinstance;
}


/*
  get RUDP from receiver buffer,  analyse it and make different 
  respondence according to the value of the message's field
*/
bool SOCKET_Receive_Protocol_Handler::f_SOCKET_Receive_Analyse_Protocol_Handler(Data_Queue_STR* data_queue_str)
{
	RUDP* rudp;
	rudp=(RUDP*)data_queue_str->rudp_data;
	cout<<"源设备号:"<<rudp->S_deviceID<<endl;
	cout<<"目的设备号:"<<rudp->D_deviceID<<endl;
	
//包类型为0代表数据包,否则为控制包
	if(rudp->packet_type=='0')
	{
		cout<<"接收包的序列号"<<rudp->packet_seq<<endl;
		cout<<"想要包的序列号"<<sequence_manager_ptr->f_get_desired(rudp->S_deviceID)<<endl;
		if(rudp->packet_seq==sequence_manager_ptr->f_get_desired(rudp->S_deviceID))
		{
			sequence_manager_ptr->f_get_desired_packet(rudp->S_deviceID);
			control_manager_pter->f_SOCKET_ACK_Send(rudp->D_deviceID, rudp->S_deviceID, rudp->packet_seq);
		}
		else
		{
			control_manager_pter->f_SOCKET_ACK_Send(rudp->D_deviceID, rudp->S_deviceID, sequence_manager_ptr->f_get_desired(rudp->S_deviceID)-1);
		}
	}   
	else            //处理控制包
	{
		control_manager_pter->f_SOCKET_Control_RUDP_Analyse_Handler(data_queue_str);
	}
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -