예제 #1
0
파일: GoAwayTests.cs 프로젝트: lulzzz/Port
 protected override Task GivenAsync(
     CancellationToken cancellationToken)
 {
     _frame = GoAway.InternalError(
         UInt31.From(123));
     return(Task.CompletedTask);
 }
예제 #2
0
 protected override Task GivenAsync(
     CancellationToken cancellationToken)
 {
     _frame = new WindowUpdate(
         UInt31.From(123),
         UInt31.From(542));
     return(Task.CompletedTask);
 }
예제 #3
0
파일: DataTests.cs 프로젝트: lulzzz/Port
 protected override Task GivenAsync(
     CancellationToken cancellationToken)
 {
     _frame = Data.Last(
         UInt31.From(123),
         Encoding.UTF8.GetBytes("this is a payload"));
     return(Task.CompletedTask);
 }
예제 #4
0
파일: HeadersTests.cs 프로젝트: lulzzz/Port
 protected override Task GivenAsync(
     CancellationToken cancellationToken)
 {
     _frame = Headers.Last(
         UInt31.From(123),
         new NameValueHeaderBlock(
             ("host", new [] { "test" }),
             ("user-agent",
              new [] { "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv: 50.0) Gecko / 20100101 Firefox / 50.0" })));
     return(Task.CompletedTask);
 }
예제 #5
0
파일: Control.cs 프로젝트: lulzzz/Port
        internal new static async ValueTask <ReadResult <Control> > TryReadAsync(
            IFrameReader frameReader,
            CancellationToken cancellation = default)
        {
            var version =
                (ushort)(await frameReader.ReadUShortAsync(cancellation)
                         .ConfigureAwait(false) & 0x7FFF);

            if (version != Version)
            {
                // todo: What stream id should be specified here?
                return(ReadResult <Control> .Error(RstStream.UnsupportedVersion(UInt31.From(0))));
            }

            var type = await frameReader.ReadUShortAsync(cancellation)
                       .ConfigureAwait(false);

            var flags = await frameReader.ReadByteAsync(cancellation)
                        .ConfigureAwait(false);

            var length = await frameReader.ReadUInt24Async(cancellation)
                         .ConfigureAwait(false);

            return(type switch
            {
                SynStream.Type => (await SynStream.TryReadAsync(
                                       flags, length, frameReader, cancellation)
                                   .ConfigureAwait(false)).AsControl(),
                SynReply.Type => (await SynReply.TryReadAsync(
                                      flags, length, frameReader, cancellation)
                                  .ConfigureAwait(false)).AsControl(),
                RstStream.Type => (await RstStream.TryReadAsync(
                                       flags, length, frameReader, cancellation)
                                   .ConfigureAwait(false)).AsControl(),
                Settings.Type => (await Settings.TryReadAsync(
                                      flags, length, frameReader, cancellation)
                                  .ConfigureAwait(false)).AsControl(),
                Ping.Type => (await Ping.TryReadAsync(
                                  flags, length, frameReader, cancellation)
                              .ConfigureAwait(false)).AsControl(),
                GoAway.Type => (await GoAway.TryReadAsync(
                                    flags, length, frameReader, cancellation)
                                .ConfigureAwait(false)).AsControl(),
                Headers.Type => (await Headers.TryReadAsync(
                                     flags, length, frameReader, cancellation)
                                 .ConfigureAwait(false)).AsControl(),
                WindowUpdate.Type => (await WindowUpdate.TryReadAsync(
                                          flags, length, frameReader, cancellation)
                                      .ConfigureAwait(false)).AsControl(),
                _ => throw new ArgumentOutOfRangeException(
                    nameof(type), $"Unknown control frame type {type} received")
            });
예제 #6
0
 protected override Task GivenAsync(
     CancellationToken cancellationToken)
 {
     _frame = new SynStream(
         SynStream.Options.Unidirectional,
         UInt31.From(123),
         UInt31.From(524),
         SynStream.PriorityLevel.High,
         new NameValueHeaderBlock(
             ("host", new[] { "test", "test2" }),
             ("user-agent",
              new[]
     {
         "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv: 50.0) Gecko / 20100101 Firefox / 50.0"
     })));
     return(Task.CompletedTask);
 }
예제 #7
0
파일: Data.cs 프로젝트: lulzzz/Port
        internal new static async ValueTask <ReadResult <Data> > TryReadAsync(
            IFrameReader frameReader,
            CancellationToken cancellation = default)
        {
            // Since bit 31 is the control bit which is 0 for data frames,
            // there is no need to blank it out
            var streamId = UInt31.From(
                await frameReader.ReadUInt32Async(cancellation)
                .ConfigureAwait(false));
            var flags = await frameReader.ReadByteAsync(cancellation)
                        .ConfigureAwait(false);

            var length = await frameReader.ReadUInt24Async(cancellation)
                         .ConfigureAwait(false);

            var payload = await frameReader.ReadBytesAsync(
                (int)length.Value, cancellation)
                          .ConfigureAwait(false);

            return(ReadResult.Ok(new Data(streamId, flags.ToEnum <Options>(), payload)));
        }
예제 #8
0
파일: SpdySession.cs 프로젝트: lulzzz/Port
        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);
                }
            }));
예제 #9
0
파일: GoAwayTests.cs 프로젝트: lulzzz/Port
 public void It_should_have_last_good_stream_id()
 {
     _message.LastGoodStreamId.Should()
     .Be(UInt31.From(123));
 }
예제 #10
0
 internal static async ValueTask <UInt31> AsUInt31Async(
     this ValueTask <uint> value)
 {
     return(UInt31.From(await value
                        .ConfigureAwait(false) & 0x7FFFFFFF));
 }
예제 #11
0
 protected override Task GivenAsync(CancellationToken cancellationToken)
 {
     _frame = RstStream.Cancel(
         UInt31.From(123));
     return(Task.CompletedTask);
 }