Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 protected override Task GivenAsync(
     CancellationToken cancellationToken)
 {
     _frame = GoAway.InternalError(
         UInt31.From(123));
     return(Task.CompletedTask);
 }
Exemplo n.º 3
0
 protected override async Task WhenAsync(
     CancellationToken cancellationToken)
 {
     _message =
         (GoAway)(await Control.TryReadAsync(
                      new FrameReader(
                          PipeReader.Create(_serialized)),
                      cancellationToken)
                  .ConfigureAwait(false)).Result;
 }
Exemplo n.º 4
0
        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);
                }
            }));
Exemplo n.º 5
0
 void Awake()
 {
     manage = this;
 }