/// <summary> /// This class defines GoAway frame. /// </summary> /// <param name="lastStreamId">The last stream id.</param> /// <param name="statusCode">The rest status code.</param> public GoAwayFrame(int lastStreamId, ErrorCodeRegistry statusCode) : base(new byte[InitialFrameSize]) { FrameType = OpCodeFrame.Go_Away; PayloadLength = InitialFrameSize - Constants.FramePreambleSize; // 16 bytes LastGoodStreamId = lastStreamId; StatusCode = statusCode; }
/// <summary> /// Reset stream frame class. /// </summary> /// <param name="id">The id.</param> /// <param name="statusCode">The rest status code.</param> public RstStreamFrame(int id, ErrorCodeRegistry statusCode) : base(new byte[InitialFrameSize]) { StreamId = id; //32 bit FrameType = OpCodeFrame.Reset_Stream; //8bit PayloadLength = InitialFrameSize - Constants.FramePreambleSize; // 32bit StatusCode = statusCode; //32bit }
/// <summary> /// Process close connection frame. /// </summary> /// <param name="httpContext">The current http context.</param> /// <param name="errorCode">Error code registry.</param> /// <param name="stream">The current stream.</param> internal static void ProcessClose(Nequeo.Net.Http2.HttpContext httpContext, ErrorCodeRegistry errorCode, ContextStream stream) { // If the stream has been cancelled of an internal error. if (errorCode == ErrorCodeRegistry.Cancel || errorCode == ErrorCodeRegistry.Internal_Error) { ProcessCloseRstStreamFrame(httpContext, errorCode, stream.StreamId); } // Close flow control manager. stream.FlowControlManager.StreamClosedHandler(stream); // Indicate the stream is closed. stream.Closed = true; stream.Opened = false; // Remove the stream from this list. httpContext.RemoveStream(stream.StreamId); }
/// <summary> /// Generic protocol error exception. /// </summary> /// <param name="code">The error code.</param> /// <param name="message">The message.</param> public ProtocolError(ErrorCodeRegistry code, string message) : base(message) { Code = code; }
/// <summary> /// Proess close rest stream frame. /// </summary> /// <param name="httpContext">The current http context.</param> /// <param name="errorCode">Error code registry.</param> /// <param name="streamID">The current stream id.</param> internal static void ProcessCloseRstStreamFrame(Nequeo.Net.Http2.HttpContext httpContext, ErrorCodeRegistry errorCode, int streamID) { // Create the reset stream frame response. RstStreamFrame frame = new RstStreamFrame(streamID, errorCode); // Write the frame. httpContext.ResponseWrite(frame.Buffer); }
/// <summary> /// Proess close goaway frame. /// </summary> /// <param name="httpContext">The current http context.</param> /// <param name="errorCode">Error code registry.</param> /// <param name="lastStreamID">The last good stream id.</param> private static void ProcessCloseGoAwayFrame(Nequeo.Net.Http2.HttpContext httpContext, ErrorCodeRegistry errorCode, int lastStreamID) { // Create the goaway frame response. GoAwayFrame frame = new GoAwayFrame(lastStreamID, errorCode); // Write the frame. httpContext.ResponseWrite(frame.Buffer); }
/// <summary> /// Process close connection frame. /// </summary> /// <param name="httpContext">The current http context.</param> /// <param name="errorCode">Error code registry.</param> private static void ProcessCloseFrame(Nequeo.Net.Http2.HttpContext httpContext, ErrorCodeRegistry errorCode) { // Dispose of all session streams foreach (var stream in httpContext.ContextStreams.Values) { // Cancel the stream. ProcessClose(httpContext, ErrorCodeRegistry.No_Error, stream); } // Create the GoAway frame. // If there is only the control stream zero then use that // else try get the last good stream that was used. ProcessCloseGoAwayFrame(httpContext, errorCode, httpContext.ContextStreams.Count > 0 ? httpContext.StreamId : 0); // Wait for a while, to let all data to be sent. using (var goAwayDelay = new ManualResetEvent(false)) { goAwayDelay.WaitOne(500); } }