/// <summary> /// packets are written by the endpoint /// </summary> /// <param name="p"></param> public void receive(UDTPacket p) { if (storeStatistics) { dgReceiveInterval.end(); } handoffQueue.Enqueue(p); if (storeStatistics) { dgReceiveInterval.begin(); } }
/// <summary> /// sends the given data packet, storing the relevant information /// 发送存储相关信息的数据包 /// </summary> /// <param name="p"></param> private void send(DataPacket p) { lock (sendLock) { if (storeStatistics) { dgSendInterval.end(); dgSendTime.begin(); } endpoint.doSend(p); if (storeStatistics) { dgSendTime.end(); dgSendInterval.begin(); throughput.end(); throughput.begin(); } sendBuffer[p.getPacketSequenceNumber()] = p; unacknowledged.IncrementAndGet(); } statistics.incNumberOfSentDataPackets(); }
protected void processUDTPacket(UDTPacket p) { //(3).Check the packet type and process it according to this. try { if (!p.isControlPacket()) { DataPacket dp = (DataPacket)p; if (storeStatistics) { dataPacketInterval.end(); dataProcessTime.begin(); } onDataPacketReceived(dp);//解析数据包将数据存在AppData类中 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(); } } catch (Exception exc) { Log.Write(this.ToString(), exc); } }
/// <summary> /// receiver algorithm /// see specification P11. /// </summary> public void receiverAlgorithm() { try { if (handoffQueue.Count <= 0) { Thread.Yield(); } else { //check ACK timer long currentTime = Util.getCurrentTime(); #region 暂时,屏蔽不然会一直发包(不知道这段是启什么作用) //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(); //} #endregion //perform time-bounded UDP receive UDTPacket packet = handoffQueue.Dequeue(); 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(); } //解析数据包将数据存在AppData类中 processUDTPacket(packet); if (storeStatistics) { processTime.end(); } } Thread.Yield(); } } catch (Exception exc) { Log.Write(this.ToString(), exc); } }