Remove extra FrameContext class

Resolves #837
This commit is contained in:
Ben Adams 2016-05-19 02:16:09 +01:00
parent 7e7f21ec49
commit e8647c0cb4
7 changed files with 17 additions and 34 deletions

View File

@ -73,6 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
MaybeExtra.Add(new KeyValuePair<Type, object>(key, value)); MaybeExtra.Add(new KeyValuePair<Type, object>(key, value));
} }
public IFrameControl FrameControl { get; set; }
string IHttpRequestFeature.Protocol string IHttpRequestFeature.Protocol
{ {

View File

@ -20,7 +20,7 @@ using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Server.Kestrel.Http namespace Microsoft.AspNetCore.Server.Kestrel.Http
{ {
public abstract partial class Frame : FrameContext, IFrameControl public abstract partial class Frame : ConnectionContext, IFrameControl
{ {
private static readonly Encoding _ascii = Encoding.ASCII; private static readonly Encoding _ascii = Encoding.ASCII;
private static readonly ArraySegment<byte> _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment<byte> _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n");

View File

@ -1,18 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Server.Kestrel.Http
{
public class FrameContext : ConnectionContext
{
public FrameContext()
{
}
public FrameContext(ConnectionContext context) : base(context)
{
}
public IFrameControl FrameControl { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
{ {
class FrameResponseStream : Stream class FrameResponseStream : Stream
{ {
private FrameContext _context; private IFrameControl _frameControl;
private FrameStreamState _state; private FrameStreamState _state;
public FrameResponseStream() public FrameResponseStream()
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
{ {
ValidateState(default(CancellationToken)); ValidateState(default(CancellationToken));
_context.FrameControl.Flush(); _frameControl.Flush();
} }
public override Task FlushAsync(CancellationToken cancellationToken) public override Task FlushAsync(CancellationToken cancellationToken)
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
var task = ValidateState(cancellationToken); var task = ValidateState(cancellationToken);
if (task == null) if (task == null)
{ {
return _context.FrameControl.FlushAsync(cancellationToken); return _frameControl.FlushAsync(cancellationToken);
} }
return task; return task;
} }
@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
{ {
ValidateState(default(CancellationToken)); ValidateState(default(CancellationToken));
_context.FrameControl.Write(new ArraySegment<byte>(buffer, offset, count)); _frameControl.Write(new ArraySegment<byte>(buffer, offset, count));
} }
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
var task = ValidateState(cancellationToken); var task = ValidateState(cancellationToken);
if (task == null) if (task == null)
{ {
return _context.FrameControl.WriteAsync(new ArraySegment<byte>(buffer, offset, count), cancellationToken); return _frameControl.WriteAsync(new ArraySegment<byte>(buffer, offset, count), cancellationToken);
} }
return task; return task;
} }
@ -134,14 +134,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
} }
} }
public void Initialize(FrameContext context) public void Initialize(IFrameControl frameControl)
{ {
_context = context; _frameControl = frameControl;
} }
public void Uninitialize() public void Uninitialize()
{ {
_context = null; _frameControl = null;
_state = FrameStreamState.Closed; _state = FrameStreamState.Closed;
} }

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
ServerOptions = serverOptions; ServerOptions = serverOptions;
} }
public Streams CreateStreams(FrameContext owner) public Streams CreateStreams(IFrameControl frameControl)
{ {
Streams streams; Streams streams;
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
streams = new Streams(); streams = new Streams();
} }
streams.Initialize(owner); streams.Initialize(frameControl);
return streams; return streams;
} }
@ -103,9 +103,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody);
} }
public void Initialize(FrameContext renter) public void Initialize(IFrameControl frameControl)
{ {
ResponseBody.Initialize(renter); ResponseBody.Initialize(frameControl);
} }
public void Uninitialize() public void Uninitialize()

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
{ {
KestrelServerOptions ServerOptions { get; set; } KestrelServerOptions ServerOptions { get; set; }
Streams CreateStreams(FrameContext owner); Streams CreateStreams(IFrameControl frameControl);
void DisposeStreams(Streams streams); void DisposeStreams(Streams streams);

View File

@ -18,14 +18,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
var trace = new KestrelTrace(new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace());
var ltp = new LoggingThreadPool(trace); var ltp = new LoggingThreadPool(trace);
var context = new FrameContext() var context = new Frame<object>(null, new ConnectionContext() { ServerAddress = new ServerAddress() })
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ConnectionControl = this, ConnectionControl = this,
FrameControl = this FrameControl = this
}; };
FrameContext = new Frame<object>(null, context); FrameContext = context;
_memoryPool = new MemoryPool(); _memoryPool = new MemoryPool();
FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp);