Esempio n. 1
0
        // bytes can be negative when SETTINGS_INITIAL_WINDOW_SIZE decreases mid-connection.
        // This can also cause Available to become negative which MUST be allowed.
        // https://httpwg.org/specs/rfc7540.html#rfc.section.6.9.2
        public bool TryUpdateWindow(int bytes)
        {
            if (_flow.TryUpdateWindow(bytes))
            {
                while (_flow.Available > 0 && _awaitableQueue?.Count > 0)
                {
                    _awaitableQueue.Dequeue().Complete();
                }

                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public bool TryUpdateWindow(int bytes, out int updateSize)
        {
            lock (_flowLock) {
                updateSize = 0;

                if (_flow.IsAborted)
                {
                    // All data received by stream has already been returned to the connection window.
                    return(false);
                }

                if (!_flow.TryUpdateWindow(bytes))
                {
                    // We only try to update the window back to its initial size after the app consumes data.
                    // It shouldn't be possible for the window size to ever exceed Http2PeerSettings.MaxWindowSize.
                    Debug.Assert(false, $"{nameof(TryUpdateWindow)} attempted to grow window past max size.");
                }

                if (_windowUpdatesDisabled)
                {
                    // Continue returning space to the connection window. The end of the stream has already
                    // been received, so don't send window updates for the stream window.
                    return(true);
                }

                var potentialUpdateSize = _pendingUpdateSize + bytes;

                if (potentialUpdateSize > _minWindowSizeIncrement)
                {
                    _pendingUpdateSize = 0;
                    updateSize         = potentialUpdateSize;
                }
                else
                {
                    _pendingUpdateSize = potentialUpdateSize;
                }

                return(true);
            }
        }