Example #1
0
        private async Task WriteOutputAsync(LibuvOutputConsumer consumer, PipeReader outputReader, Http1Connection http1Connection)
        {
            // This WriteOutputAsync() calling code is equivalent to that in LibuvConnection.
            try
            {
                // Ensure that outputReader.Complete() runs on the LibuvThread.
                // Without ConfigureAwait(false), xunit will dispatch.
                await consumer.WriteOutputAsync().ConfigureAwait(false);

                http1Connection.Abort(abortReason: null);
                outputReader.Complete();
            }
            catch (UvException ex)
            {
                http1Connection.Abort(new ConnectionAbortedException(ex.Message, ex));
                outputReader.Complete(ex);
            }
        }
Example #2
0
        private async Task WriteOutputAsync(LibuvOutputConsumer consumer, IPipeReader outputReader, Frame frame)
        {
            // This WriteOutputAsync() calling code is equivalent to that in LibuvConnection.
            try
            {
                // Ensure that outputReader.Complete() runs on the LibuvThread.
                // Without ConfigureAwait(false), xunit will dispatch.
                await consumer.WriteOutputAsync().ConfigureAwait(false);

                frame.Abort(error: null);
                outputReader.Complete();
            }
            catch (UvException ex)
            {
                frame.Abort(ex);
                outputReader.Complete(ex);
            }
        }
        private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null)
        {
            var pair = DuplexPipe.CreateConnectionPair(pipeOptions, pipeOptions);

            var logger         = new TestApplicationErrorLogger();
            var serviceContext = new TestServiceContext
            {
                Log       = new TestKestrelTrace(logger),
                Scheduler = PipeScheduler.Inline
            };
            var transportContext = new TestLibuvTransportContext {
                Log = new LibuvTrace(logger)
            };

            var socket   = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log);
            var consumer = new LibuvOutputConsumer(pair.Application.Input, _libuvThread, socket, "0", transportContext.Log);

            var connectionFeatures = new FeatureCollection();

            connectionFeatures.Set(Mock.Of <IConnectionLifetimeFeature>());
            connectionFeatures.Set(Mock.Of <IBytesWrittenFeature>());

            var http1Connection = new Http1Connection(new Http1ConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionContext  = Mock.Of <ConnectionContext>(),
                ConnectionFeatures = connectionFeatures,
                MemoryPool         = _memoryPool,
                TimeoutControl     = Mock.Of <ITimeoutControl>(),
                Application        = pair.Application,
                Transport          = pair.Transport
            });

            if (cts != null)
            {
                http1Connection.RequestAborted.Register(cts.Cancel);
            }

            var ignore = WriteOutputAsync(consumer, pair.Application.Input, http1Connection);

            return((Http1OutputProducer)http1Connection.Output);
        }
        private OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null)
        {
            var pipe = _pipeFactory.Create(pipeOptions);

            var logger         = new TestApplicationErrorLogger();
            var serviceContext = new TestServiceContext
            {
                Log        = new TestKestrelTrace(logger),
                ThreadPool = new InlineLoggingThreadPool(new TestKestrelTrace(logger))
            };
            var transportContext = new TestLibuvTransportContext {
                Log = new LibuvTrace(logger)
            };

            var socket   = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log);
            var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, "0", transportContext.Log);

            var frame = new Frame <object>(null, new FrameContext
            {
                ServiceContext        = serviceContext,
                ConnectionInformation = new MockConnectionInformation
                {
                    PipeFactory = _pipeFactory
                },
                TimeoutControl = Mock.Of <ITimeoutControl>(),
                Output         = pipe
            });

            if (cts != null)
            {
                frame.RequestAborted.Register(cts.Cancel);
            }

            var ignore = WriteOutputAsync(consumer, pipe.Reader, frame);

            return(frame.Output);
        }
        private Http1OutputProducer CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null)
        {
            var pair = _pipeFactory.CreateConnectionPair(pipeOptions, pipeOptions);

            var logger         = new TestApplicationErrorLogger();
            var serviceContext = new TestServiceContext
            {
                Log        = new TestKestrelTrace(logger),
                ThreadPool = new InlineLoggingThreadPool(new TestKestrelTrace(logger))
            };
            var transportContext = new TestLibuvTransportContext {
                Log = new LibuvTrace(logger)
            };

            var socket   = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log);
            var consumer = new LibuvOutputConsumer(pair.Application.Input, _libuvThread, socket, "0", transportContext.Log);

            var http1Connection = new Http1Connection <object>(null, new Http1ConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                PipeFactory        = _pipeFactory,
                TimeoutControl     = Mock.Of <ITimeoutControl>(),
                Application        = pair.Application,
                Transport          = pair.Transport
            });

            if (cts != null)
            {
                http1Connection.RequestAborted.Register(cts.Cancel);
            }

            var ignore = WriteOutputAsync(consumer, pair.Application.Input, http1Connection);

            return((Http1OutputProducer)http1Connection.Output);
        }