private HttpFrame DecodeGoAway(DecodingContext context, int payloadLength, byte flags, int streamIdentifier) { if (streamIdentifier != 0) { throw new DecoderException(Http2ErrorCode.ProtocolError, "GOAWAY frame must not have a stream identifier."); } var lastStreamId = BitConverter.ToInt32(context.Buffer, context.Offset) & ~Bit32; var errorCode = BitConverter.ToInt32(context.Buffer, context.Offset + 4); context.Offset += 8; context.BytesLeftToProcess -= 8; var frame = new GoAway(lastStreamId, errorCode); if (payloadLength == 8) { return(frame); } var data = new byte[payloadLength - 8]; Buffer.BlockCopy(context.Buffer, context.Offset, data, 0, payloadLength - 8); frame.DebugData = data; context.Offset += data.Length; context.BytesLeftToProcess -= data.Length; return(frame); }
protected override Task GivenAsync( CancellationToken cancellationToken) { _frame = GoAway.InternalError( UInt31.From(123)); return(Task.CompletedTask); }
protected override async Task WhenAsync( CancellationToken cancellationToken) { _message = (GoAway)(await Control.TryReadAsync( new FrameReader( PipeReader.Create(_serialized)), cancellationToken) .ConfigureAwait(false)).Result; }
private Task StartBackgroundTaskAsync( Func <Task> action, CancellationTokenSource cancellationTokenSource) { // ReSharper disable once MethodSupportsCancellation // Will gracefully handle cancellation return(Task.Run( async() => { try { await action() .ConfigureAwait(false); } catch when(cancellationTokenSource .IsCancellationRequested) { } catch (Exception ex) { _logger.Fatal(ex, "Unknown error, closing down"); await StopNetworkSenderAsync() .ConfigureAwait(false); try { await SendAsync( GoAway.InternalError( UInt31.From(_lastGoodRepliedStreamId)), SessionCancellationToken) .ConfigureAwait(false); } catch (Exception e) { _logger.Error(e, "Could not send GoAway"); } _sessionCancellationTokenSource.Cancel(false); } }));
void Awake() { manage = this; }