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

📄 congestionwindow.cs

📁 rudp可靠保障得udp传输
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Helper.Net.RUDP.Reno
{

	sealed internal class CongestionWindow : AbstractWindow
	{

		#region Variables

		//---- AIMD
		private int CA_THRESH = 4;
		private int FC_THRESH = 4;

		internal int _SlowStartThresholdSize;

		#endregion

		#region Constructor

		internal CongestionWindow(RUDPSocket rudp)
			: base(rudp)
		{
			_rudp = rudp;
		}

		#endregion

		#region Reset

		internal override void Reset()
		{
			base.Reset();

			_SlowStartThresholdSize = 30 * 1024;
		}

		#endregion

		#region OnSend_UpdateWindow

		override internal void OnSend_UpdateWindow(int payloadLength)
		{
			/*
			bool idle = _rudp._sendingPackets.Count < 1;
			if (idle && (HiResTimer.MicroSeconds - _rudp._lastSendTS) > _rudp._rto)
				_cwnd = 2 * _rudp._mtu;
			*/
		}

		#endregion

		#region OnACK_UpdateWindow

		internal override void OnACK_UpdateWindow(RUDPOutgoingPacket packet)
		{
			if (_cwnd <= _SlowStartThresholdSize)
			{
				//-- Slow start
				// Exponential grow : quick start
				// cwnd = cwnd + 1;
				_cwnd += _rudp.MTU;
			}
			else
			{
				//-- Performing congestion avoidance
				// This is a linear growth of cwnd.
				// During congestion avoidance, cwnd is incremented by 1 full-sized
				// segment per round-trip time (_rtt).
				// cwnd = cwnd + SMSS*SMSS/cwnd
				_cwnd += _rudp.MTU * _rudp.MTU / _cwnd;
			}

		}

		#endregion

		#region OnResend_UpdateWindow

		internal override void OnResend_UpdateWindow()
		{
			// amount of data that has been sent but not yet acknowledged (acked).
			int FlightSize = (int)(_cwnd - _SlowStartThresholdSize);

			if (_cwnd < _SlowStartThresholdSize ||
				_SlowStartThresholdSize < CA_THRESH ||
				FlightSize < FC_THRESH)
			{
				// Slow down
				_SlowStartThresholdSize = Math.Max(Math.Min(_rudp._sendSize, (int)_cwnd) / 2, 2);
				_cwnd = 2 * _rudp._mtu;
			}
			else
			{
				//---- Fast retransmit / Fast recovery
				_SlowStartThresholdSize = (int)(_cwnd - _SlowStartThresholdSize / 2);
				//Math.Min(_rudp._sendSize / 2, Math.Max(_SlowStartThresholdSize, 2));
				_cwnd = _SlowStartThresholdSize;
			}
		}

		#endregion

	}

}

⌨️ 快捷键说明

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