protected void ProcessUDTPacket(IUDTPacket p) { //(3).Check the packet type and process it according to this. if (!p.IsControlPacket()) { DataPacket dp = (DataPacket)p; if (storeStatistics) { dataPacketInterval.End(); dataProcessTime.Begin(); } OnDataPacketReceived(dp); if (storeStatistics) { dataProcessTime.End(); dataPacketInterval.Begin(); } } else if (p.GetControlPacketType() == (int)ControlPacketType.ACK2) { Acknowledgment2 ack2 = (Acknowledgment2)p; onAck2PacketReceived(ack2); } else if (p is Shutdown) { OnShutdown(); } }
/** * receiver algorithm * see specification P11. */ public void ReceiverAlgorithm() { //check ACK timer long currentTime = Util.getCurrentTime(); if (nextACK < currentTime) { nextACK = currentTime + ackTimerInterval; ProcessACKEvent(true); } //check NAK timer if (nextNAK < currentTime) { nextNAK = currentTime + nakTimerInterval; ProcessNAKEvent(); } //check EXP timer if (nextEXP < currentTime) { nextEXP = currentTime + expTimerInterval; ProcessEXPEvent(); } //perform time-bounded UDP receive IUDTPacket packet = null; handoffQueue.TryTake(out packet, (int)Util.GetSYNTime()); if (packet != null) { //reset exp count to 1 expCount = 1; //If there is no unacknowledged data packet, or if this is an //ACK or NAK control packet, reset the EXP timer. bool needEXPReset = false; if (packet.IsControlPacket()) { ControlPacket cp = (ControlPacket)packet; int cpType = cp.GetControlPacketType(); if (cpType == (int)ControlPacketType.ACK || cpType == (int)ControlPacketType.NAK) { needEXPReset = true; } } if (needEXPReset) { nextEXP = Util.getCurrentTime() + expTimerInterval; } if (storeStatistics) { processTime.Begin(); } ProcessUDTPacket(packet); if (storeStatistics) { processTime.End(); } } Thread.Yield(); }