Exemple #1
0
        internal void HandleMTUResponse(uint size)
        {
            _stateLock.EnterReadLock();

            try
            {
                if (State == ConnectionState.Connected)
                {
                    // Calculate the new MTU
                    int attemptedMtu = (int)(MTU * Config.MTUGrowthFactor);

                    if (attemptedMtu > Config.MaximumMTU)
                    {
                        attemptedMtu = Config.MaximumMTU;
                    }

                    if (attemptedMtu < Config.MinimumMTU)
                    {
                        attemptedMtu = Config.MinimumMTU;
                    }

                    if (attemptedMtu == size)
                    {
                        // This is a valid response

                        if (Merger != null)
                        {
                            Merger.ExpandToSize((int)attemptedMtu);
                        }

                        // Set new MTU
                        MTU = (ushort)attemptedMtu;

                        // Set new status
                        MTUStatus = new MessageStatus()
                        {
                            Attempts    = 0,
                            HasAcked    = false,
                            LastAttempt = NetTime.MinValue
                        };

                        if (Logging.CurrentLogLevel <= LogLevel.Debug)
                        {
                            Logging.LogInfo("Client " + EndPoint + " MTU was increased to " + MTU);
                        }
                    }
                }
            }
            finally
            {
                _stateLock.ExitReadLock();
            }
        }