// Outgoing
 public RstStreamFrame(int id, ResetStatusCode statusCode)
     : base(new byte[InitialFrameSize], id)
 {
     FrameType = ControlFrameType.RstStream;
     FrameLength = InitialFrameSize - Constants.FramePreambleSize; // 8
     StatusCode = statusCode;
 }
예제 #2
0
        public void Close(ResetStatusCode code)
        {
            if (Closed || Idle)
            {
                return;
            }

            OnFrameSent = null;

            Http2Logger.LogDebug("Total outgoing data frames volume " + SentDataAmount);
            Http2Logger.LogDebug("Total frames sent: {0}", FramesSent);
            Http2Logger.LogDebug("Total frames received: {0}", FramesReceived);

            if (code == ResetStatusCode.Cancel || code == ResetStatusCode.InternalError)
            {
                WriteRst(code);
            }

            _flowCrtlManager.StreamClosedHandler(this);

            Closed = true;

            if (OnClose != null)
            {
                OnClose(this, new StreamClosedEventArgs(_id));
            }

            OnClose = null;

            Http2Logger.LogDebug("Stream closed " + _id);
        }
예제 #3
0
 // Outgoing
 public RstStreamFrame(int id, ResetStatusCode statusCode)
     : base(new byte[InitialFrameSize])
 {
     StreamId    = id;                                             //32 bit
     FrameType   = FrameType.RstStream;                            //8bit
     FrameLength = InitialFrameSize - Constants.FramePreambleSize; // 16bit
     StatusCode  = statusCode;                                     //32bit
 }
예제 #4
0
 // Outgoing
 public GoAwayFrame(int lastStreamId, ResetStatusCode statusCode)
     : base(new byte[InitialFrameSize])
 {
     FrameType        = FrameType.GoAway;
     FrameLength      = InitialFrameSize - Constants.FramePreambleSize; // 16 bytes
     LastGoodStreamId = lastStreamId;
     StatusCode       = statusCode;
 }
예제 #5
0
 // Outgoing
 public GoAwayFrame(int lastStreamId, ResetStatusCode statusCode)
     : base(new byte[InitialFrameSize])
 {
     FrameType = FrameType.GoAway;
     FrameLength = InitialFrameSize - Constants.FramePreambleSize; // 16 bytes
     LastGoodStreamId = lastStreamId;
     StatusCode = statusCode;
 }
예제 #6
0
 // Outgoing
 public RstStreamFrame(int id, ResetStatusCode statusCode)
     : base(new byte[InitialFrameSize])
 {
     StreamId = id;//32 bit
     FrameType = FrameType.RstStream;//8bit
     FrameLength = InitialFrameSize - Constants.FramePreambleSize; // 16bit
     StatusCode = statusCode;//32bit
 }
예제 #7
0
        public void WriteRst(ResetStatusCode code)
        {
            var frame = new RstStreamFrame(_id, code);

            _writeQueue.WriteFrame(frame);
            ResetSent = true;

            if (OnFrameSent != null)
            {
                OnFrameSent(this, new FrameSentArgs(frame));
            }
        }
예제 #8
0
        /// <summary>
        /// Writes the go away frame.
        /// </summary>
        /// <param name="code">The code.</param>
        public void WriteGoAway(ResetStatusCode code)
        {
            //if there were no streams opened
            if (_lastId == -1)
            {
                _lastId = 0; //then set lastId to 0 as spec tells. (See GoAway chapter)
            }

            var frame = new GoAwayFrame(_lastId, code);

            _writeQueue.WriteFrame(frame);
        }
예제 #9
0
        /// <summary>
        /// Writes the GOAWAY frame.
        /// </summary>
        /// <param name="code">The Reset Status code.</param>
        public void WriteGoAway(ResetStatusCode code)
        {
            //if there were no streams opened
            if (_lastId == -1)
            {
                _lastId = 0; //then set lastId to 0 as spec tells. (See GoAway chapter)
            }

            var frame = new GoAwayFrame(_lastId, code);

            Http2Logger.LogDebug("Sending GOAWAY frame: stream id={0}, code={1}, last good id={2}",
                                 frame.StreamId, frame.StatusCode, frame.LastGoodStreamId);

            _writeQueue.WriteFrame(frame);
        }
예제 #10
0
        public void WriteRst(ResetStatusCode code)
        {
            if (Closed)
            {
                return;
            }

            var frame = new RstStreamFrame(_id, code);

            _writeQueue.WriteFrame(frame);

            if (OnFrameSent != null)
            {
                OnFrameSent(this, new FrameSentEventArgs(frame));
            }
        }
예제 #11
0
        private void Close(ResetStatusCode status)
        {
            if (_disposed)
            {
                return;
            }

            Http2Logger.LogDebug("Session closing");
            _disposed = true;

            // Dispose of all streams
            foreach (Http2Stream stream in ActiveStreams.Values)
            {
                //Cancel all opened streams
                stream.WriteRst(ResetStatusCode.Cancel);
                stream.Dispose();
            }

            OnSettingsSent  = null;
            OnFrameReceived = null;
            OnFrameSent     = null;

            if (!_goAwayReceived)
            {
                WriteGoAway(status);

                if (_writeQueue != null)
                {
                    _writeQueue.Flush();
                    _writeQueue.Dispose();
                }
            }

            _comprProc.Dispose();
            _sessionSocket.Close();

            if (OnSessionDisposed != null)
            {
                OnSessionDisposed(this, null);
            }
            OnSessionDisposed = null;

            Http2Logger.LogDebug("Session closed");
        }
예제 #12
0
 public ProtocolError(ResetStatusCode code, string message): base(message)
 {
     Code = code;
 }
예제 #13
0
        private void Close(ResetStatusCode status)
        {
            if (_disposed)
            {
                return;
            }

            Http2Logger.LogDebug("Session closing");
            _disposed = true;

            // Dispose of all streams
            foreach (var stream in StreamDictionary.Values)
            {
                //Cancel all opened streams
                stream.Close(ResetStatusCode.None);
            }

            if (!_goAwayReceived)
            {
                WriteGoAway(status);

                //TODO fix delay. wait for goAway send and then dispose WriteQueue
                //Wait for GoAway send
                using (var goAwayDelay = new ManualResetEvent(false))
                {
                    goAwayDelay.WaitOne(500);
                }
            }
            OnSettingsSent  = null;
            OnFrameReceived = null;

            if (_frameReader != null)
            {
                _frameReader.Dispose();
                _frameReader = null;
            }

            if (_writeQueue != null)
            {
                _writeQueue.Flush();
                _writeQueue.Dispose();
            }

            if (_comprProc != null)
            {
                _comprProc.Dispose();
                _comprProc = null;
            }

            if (_ioStream != null)
            {
                _ioStream.Close();
                _ioStream = null;
            }

            if (_pingReceived != null)
            {
                _pingReceived.Dispose();
                _pingReceived = null;
            }

            if (_settingsAckReceived != null)
            {
                _settingsAckReceived.Dispose();
                _settingsAckReceived = null;
            }

            if (OnSessionDisposed != null)
            {
                OnSessionDisposed(this, null);
            }

            OnSessionDisposed = null;

            Http2Logger.LogDebug("Session closed");
        }
예제 #14
0
        public void Close(ResetStatusCode code)
        {
            if (Closed || Idle)
            {
                return;
            }

            OnFrameSent = null;

            Http2Logger.LogDebug("Total outgoing data frames volume " + SentDataAmount);
            Http2Logger.LogDebug("Total frames sent: {0}", FramesSent);
            Http2Logger.LogDebug("Total frames received: {0}", FramesReceived);

            if (code == ResetStatusCode.Cancel || code == ResetStatusCode.InternalError)
                WriteRst(code);

            _flowCrtlManager.StreamClosedHandler(this);

            Closed = true;

            if (OnClose != null)
                OnClose(this, new StreamClosedEventArgs(_id));

            OnClose = null;

            Http2Logger.LogDebug("Stream closed " + _id);
        }
예제 #15
0
        public void WriteRst(ResetStatusCode code)
        {
            if (Closed)
                return;

            var frame = new RstStreamFrame(_id, code);
            
            _writeQueue.WriteFrame(frame);

            if (OnFrameSent != null)
            {
                OnFrameSent(this, new FrameSentEventArgs(frame));
            }
        }
예제 #16
0
        private void Close(ResetStatusCode status)
        {
            if (_disposed)
                return;

            Http2Logger.LogDebug("Session closing");
            _disposed = true;

            // Dispose of all streams
            foreach (var stream in ActiveStreams.Values)
            {
                //Cancel all opened streams
                stream.Dispose(ResetStatusCode.Cancel);
            }

            if (!_goAwayReceived)
                WriteGoAway(status);

            OnSettingsSent = null;
            OnFrameReceived = null;

            //Missing GoAway means connection was forcibly closed by the remote ep. This means that we can
            //send nothing into this connection. No need trying to send GoAway.
            //Hence we may not check for !_goAwayReceived

            if (_writeQueue != null)
            {
                _writeQueue.Flush();
                _writeQueue.Dispose();
            }

            if (_frameReader != null)
            {
                _frameReader.Dispose();
                _frameReader = null;
            }

            if (_comprProc != null)
            {
                _comprProc.Dispose();
                _comprProc = null;
            }

            if (_ioStream != null)
            {
                _ioStream.Close();
                _ioStream = null;
            }

            if (_pingReceived != null)
            {
                _pingReceived.Dispose();
                _pingReceived = null;
            }

            if (_settingsAckReceived != null)
            {
                _settingsAckReceived.Dispose();
                _settingsAckReceived = null;
            }

            if (OnSessionDisposed != null)
            {
                OnSessionDisposed(this, null);
            }

            OnSessionDisposed = null;

            Http2Logger.LogDebug("Session closed");
        }
예제 #17
0
        /// <summary>
        /// Writes the GOAWAY frame.
        /// </summary>
        /// <param name="code">The Reset Status code.</param>
        public void WriteGoAway(ResetStatusCode code)
        {           
            //if there were no streams opened
            if (_lastId == -1)
            {
                _lastId = 0; //then set lastId to 0 as spec tells. (See GoAway chapter)
            }

            var frame = new GoAwayFrame(_lastId, code);

            Http2Logger.LogDebug("Sending GOAWAY frame: stream id={0}, code={1}, last good id={2}",
                frame.StreamId, frame.StatusCode, frame.LastGoodStreamId);

            _writeQueue.WriteFrame(frame);
        }
예제 #18
0
        private void Close(ResetStatusCode status)
        {
            if (_disposed)
                return;

            Http2Logger.LogDebug("Session closing");
            _disposed = true;

            // Dispose of all streams
            foreach (var stream in StreamDictionary.Values)
            {
                //Cancel all opened streams
                stream.Close(ResetStatusCode.None);
            }

            if (!_goAwayReceived)
            {
                WriteGoAway(status);

                //TODO fix delay. wait for goAway send and then dispose WriteQueue
                //Wait for GoAway send
                using (var goAwayDelay = new ManualResetEvent(false))
                {
                    goAwayDelay.WaitOne(500);
                }
            }
            OnSettingsSent = null;
            OnFrameReceived = null;

            if (_frameReader != null)
            {
                _frameReader.Dispose();
                _frameReader = null;
            }

            if (_writeQueue != null)
            {
                _writeQueue.Flush();
                _writeQueue.Dispose();
            }

            if (_comprProc != null)
            {
                _comprProc.Dispose();
                _comprProc = null;
            }

            if (_ioStream != null)
            {
                _ioStream.Close();
                _ioStream = null;
            }

            if (_pingReceived != null)
            {
                _pingReceived.Dispose();
                _pingReceived = null;
            }

            if (_settingsAckReceived != null)
            {
                _settingsAckReceived.Dispose();
                _settingsAckReceived = null;
            }

            if (OnSessionDisposed != null)
            {
                OnSessionDisposed(this, null);
            }

            OnSessionDisposed = null;

            Http2Logger.LogDebug("Session closed");
        }
예제 #19
0
 public ProtocolError(ResetStatusCode code, string message) : base(message)
 {
     Code = code;
 }
예제 #20
0
        /// <summary>
        /// Writes the go away frame.
        /// </summary>
        /// <param name="code">The code.</param>
        public void WriteGoAway(ResetStatusCode code)
        {
            //if there were no streams opened
            if (_lastId == -1)
            {
                _lastId = 0; //then set lastId to 0 as spec tells. (See GoAway chapter)
            }

            var frame = new GoAwayFrame(_lastId, code);

            _writeQueue.WriteFrame(frame);
        }
예제 #21
0
        public void WriteRst(ResetStatusCode code)
        {
            var frame = new RstStreamFrame(_id, code);
            _writeQueue.WriteFrame(frame);
            ResetSent = true;

            if (OnFrameSent != null)
            {
                OnFrameSent(this, new FrameSentArgs(frame));
            }
        }
예제 #22
0
        private void Close(ResetStatusCode status)
        {
            if (_disposed)
                return;

            Http2Logger.LogDebug("Session closing");
            _disposed = true;

            // Dispose of all streams
            foreach (Http2Stream stream in ActiveStreams.Values)
            {
                //Cancel all opened streams
                stream.WriteRst(ResetStatusCode.Cancel);
                stream.Dispose();
            }

            OnSettingsSent = null;
            OnFrameReceived = null;
            OnFrameSent = null;

            if (!_goAwayReceived)
            {
                WriteGoAway(status);

                if (_writeQueue != null)
                {
                    _writeQueue.Flush();
                    _writeQueue.Dispose();
                }
            }

            _comprProc.Dispose();
            _sessionSocket.Close();

            if (OnSessionDisposed != null)
            {
                OnSessionDisposed(this, null);
            }
            OnSessionDisposed = null;

            Http2Logger.LogDebug("Session closed");
        }
        public virtual void Reset(ResetStatusCode statusCode)
        {
            ResetReceived = true;
            if (_outputStream != null)
            {
                _outputStream.Dispose();
            }
            if (_incomingStream != null && _incomingStream != Stream.Null && !FinReceived)
            {
                InputStream inputStream = (InputStream)_incomingStream;
                inputStream.Abort(statusCode.ToString());
            }

            // Not disposing here because many of the resources may still be in use.
        }