Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpeudp.RdpeudpSocket.ManageRetransmit C# (CSharp) Method

ManageRetransmit() private method

Function used to manage retransmit periodically
private ManageRetransmit ( object state ) : void
state object
return void
        private void ManageRetransmit(object state)
        {
            if (!Connected)
            {
                return;
            }

            if (TransMode == TransportMode.Lossy)
            {
                // No need to retransmit packet if connection is lossy
                return;
            }

            // This timer MUST fire at the minimum retransmit time-out or twice the RTT, whichever is longer, after the datagram is first transmitted
            // RDPUDP_PROTOCOL_VERSION_1: the minimum retransmit time-out is 500 ms.
            // RDPUDP_PROTOCOL_VERSION_2: the minimum retransmit time-out is 300 ms.
            TimeSpan _retransmitDuration = SocketConfig.RetransmitDuration_V1;
            if(HighestVersion == uUdpVer_Values.RDPUDP_PROTOCOL_VERSION_2)
            {
                _retransmitDuration = SocketConfig.RetransmitDuration_V2;
            }

            TimeSpan retransmitDuration = ((RTT + RTT) > _retransmitDuration) ? (RTT + RTT) : _retransmitDuration;
            // Packets may need to retransmit must in send window
            uint curpos = SendWindowStartPosition;
            while (outPacketDic.ContainsKey(curpos)
                && (outPacketDic[curpos].retransmitTimes > 0 || outPacketDic[curpos].SendTime + retransmitDuration <= DateTime.Now))
            {
                if (outPacketDic[curpos].SendTime + retransmitDuration <= DateTime.Now)
                {
                    RetransmitPacket(outPacketDic[curpos].Packet);
                }
                curpos++;
            }
        }