Example #1
0
        public void ProcessReceivedFrames(IFrame frame)
        {
            switch (State)
            {
            case StreamState.Idle:
                if (frame.Type == FrameType.Headers)
                {
                    State = StreamState.Open;
                }
                else if (frame.Type == FrameType.PushPromise)
                {
                    State = StreamState.ReservedRemote;
                }
//                else if (frame.Type == FrameType.Priority)
//                    ;
//                else
//                    ;
                break;

            case StreamState.ReservedLocal:
                if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
                break;

            case StreamState.HalfClosedRemote:
                if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
                break;

            case StreamState.Open:
                if (frame.IsEndStream)
                {
                    State = StreamState.HalfClosedRemote;
                }
                if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
                break;

            case StreamState.ReservedRemote:
                if (frame.Type == FrameType.Headers)
                {
                    State = StreamState.HalfClosedLocal;
                }
                else if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
                break;

            case StreamState.HalfClosedLocal:
                if (frame.IsEndStream || frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
                break;
            }

            // Server has cleared up more window space
            // Add more to the available window
            if (frame.Type == FrameType.WindowUpdate)
            {
                var windowUpdateFrame = (WindowUpdateFrame)frame;
                flowControlStateManager.IncreaseWindowSize(StreamIdentifer, windowUpdateFrame.WindowSizeIncrement);
            }

            // Raise the event
            if (OnFrameReceived != null)
            {
                OnFrameReceived.Invoke(frame);
            }
        }
Example #2
0
        public void ProcessReceivedFrames(IFrame frame)
        {
            // Add frame to the list of history
            ReceivedFrames.Add(frame);

            if (State == StreamState.Idle)
            {
                if (frame.Type == FrameType.Headers)
                {
                    State = StreamState.Open;
                }
                else if (frame.Type == FrameType.PushPromise)
                {
                    State = StreamState.ReservedRemote;
                }
                else if (frame.Type == FrameType.Priority)
                {
                    ;
                }
                else
                {
                    ; // TODO: PROTOCOL_ERROR
                }
            }
            else if (State == StreamState.ReservedLocal)
            {
                if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
            }
            else if (State == StreamState.HalfClosedRemote)
            {
                if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
            }
            else if (State == StreamState.Open)
            {
                if (frame.IsEndStream)
                {
                    State = StreamState.HalfClosedRemote;
                }
                if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
            }
            else if (State == StreamState.ReservedRemote)
            {
                if (frame.Type == FrameType.Headers)
                {
                    State = StreamState.HalfClosedLocal;
                }
                else if (frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
            }
            else if (State == StreamState.HalfClosedLocal)
            {
                if (frame.IsEndStream || frame.Type == FrameType.RstStream)
                {
                    State = StreamState.Closed;
                }
            }

            // Server has cleared up more window space
            // Add more to the available window
            if (frame.Type == FrameType.WindowUpdate)
            {
                var windowUpdateFrame = (WindowUpdateFrame)frame;
                flowControlStateManager.IncreaseWindowSize(StreamIdentifer, windowUpdateFrame.WindowSizeIncrement);
            }

            // Raise the event
            OnFrameReceived?.Invoke(frame);
        }