diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 36de9ce5ca..a6fd1b40bb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -2,42 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; using Microsoft.AspNet.Server.Kestrel.Networking; using System.Diagnostics; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ConnectionContext : ListenerContext - { - public ConnectionContext() - { - } - - public ConnectionContext(ListenerContext context) : base(context) - { - } - - public ConnectionContext(ConnectionContext context) : base(context) - { - SocketInput = context.SocketInput; - SocketOutput = context.SocketOutput; - ConnectionControl = context.ConnectionControl; - } - - public SocketInput SocketInput { get; set; } - public ISocketOutput SocketOutput { get; set; } - - public IConnectionControl ConnectionControl { get; set; } - } - - public interface IConnectionControl - { - void Pause(); - void Resume(); - void End(ProduceEndType endType); - } - public class Connection : ConnectionContext, IConnectionControl { private static readonly Action _readCallback = ReadCallback; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs new file mode 100644 index 0000000000..cedfc63aeb --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs @@ -0,0 +1,25 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class ConnectionContext : ListenerContext + { + public ConnectionContext() + { + } + + public ConnectionContext(ListenerContext context) : base(context) + { + } + + public ConnectionContext(ConnectionContext context) : base(context) + { + SocketInput = context.SocketInput; + SocketOutput = context.SocketOutput; + ConnectionControl = context.ConnectionControl; + } + + public SocketInput SocketInput { get; set; } + public ISocketOutput SocketOutput { get; set; } + + public IConnectionControl ConnectionControl { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 1b86736968..3ae0d60b6b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -13,35 +13,6 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { - - public enum ProduceEndType - { - SocketShutdownSend, - SocketDisconnect, - ConnectionKeepAlive, - } - - public class FrameContext : ConnectionContext - { - public FrameContext() - { - - } - - public FrameContext(ConnectionContext context) : base(context) - { - - } - - public IFrameControl FrameControl { get; set; } - } - - public interface IFrameControl - { - void ProduceContinue(); - void Write(ArraySegment data, Action callback, object state); - } - public class Frame : FrameContext, IFrameControl { enum Mode diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs new file mode 100644 index 0000000000..dedcb1b41f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs @@ -0,0 +1,17 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class FrameContext : ConnectionContext + { + public FrameContext() + { + + } + + public FrameContext(ConnectionContext context) : base(context) + { + + } + + public IFrameControl FrameControl { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs new file mode 100644 index 0000000000..f0be1f74d6 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs @@ -0,0 +1,9 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public interface IConnectionControl + { + void Pause(); + void Resume(); + void End(ProduceEndType endType); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs new file mode 100644 index 0000000000..3dfab0893a --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs @@ -0,0 +1,10 @@ +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public interface IFrameControl + { + void ProduceContinue(); + void Write(ArraySegment data, Action callback, object state); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs new file mode 100644 index 0000000000..6e28b4529f --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs @@ -0,0 +1,32 @@ +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public interface IMemoryPool + { + byte[] Empty { get; } + + byte[] AllocByte(int minimumSize); + void FreeByte(byte[] memory); + + char[] AllocChar(int minimumSize); + void FreeChar(char[] memory); + + /// + /// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind + /// buffers to reduce number of array segments pinned + /// + /// The smallest length of the ArraySegment.Count that may be returned + /// An array segment which is a sub-block of a larger allocation + ArraySegment AllocSegment(int minimumSize); + + /// + /// Frees a sub-segment of a larger memory allocation produced by AllocSegment. The original ArraySegment + /// must be frees exactly once and must have the same offset and count that was returned by the Alloc. + /// If a segment is not freed it won't be re-used and has the same effect as a memory leak, so callers must be + /// implemented exactly correctly. + /// + /// The sub-block that was originally returned by a call to AllocSegment. + void FreeSegment(ArraySegment segment); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs new file mode 100644 index 0000000000..43dd4fb4b2 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs @@ -0,0 +1,12 @@ +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + /// + /// Operations performed for buffered socket output + /// + public interface ISocketOutput + { + void Write(ArraySegment buffer, Action callback, object state); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs index 5a2752709d..b2cf408f75 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs @@ -9,24 +9,6 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.Http { - public class ListenerContext - { - public ListenerContext() { } - - public ListenerContext(ListenerContext context) - { - Thread = context.Thread; - Application = context.Application; - Memory = context.Memory; - } - - public KestrelThread Thread { get; set; } - - public Func Application { get; set; } - - public IMemoryPool Memory { get; set; } - } - /// /// Summary description for Accept /// diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs new file mode 100644 index 0000000000..a2a4283a46 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public class ListenerContext + { + public ListenerContext() { } + + public ListenerContext(ListenerContext context) + { + Thread = context.Thread; + Application = context.Application; + Memory = context.Memory; + } + + public KestrelThread Thread { get; set; } + + public Func Application { get; set; } + + public IMemoryPool Memory { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs index 20e7b870bc..e08eba68fd 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -6,34 +6,6 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Server.Kestrel.Http { - public interface IMemoryPool - { - byte[] Empty { get; } - - byte[] AllocByte(int minimumSize); - void FreeByte(byte[] memory); - - char[] AllocChar(int minimumSize); - void FreeChar(char[] memory); - - /// - /// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind - /// buffers to reduce number of array segments pinned - /// - /// The smallest length of the ArraySegment.Count that may be returned - /// An array segment which is a sub-block of a larger allocation - ArraySegment AllocSegment(int minimumSize); - - /// - /// Frees a sub-segment of a larger memory allocation produced by AllocSegment. The original ArraySegment - /// must be frees exactly once and must have the same offset and count that was returned by the Alloc. - /// If a segment is not freed it won't be re-used and has the same effect as a memory leak, so callers must be - /// implemented exactly correctly. - /// - /// The sub-block that was originally returned by a call to AllocSegment. - void FreeSegment(ArraySegment segment); - } - public class MemoryPool : IMemoryPool { static readonly byte[] EmptyArray = new byte[0]; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs index 2c22d5b57f..b07f10c948 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs new file mode 100644 index 0000000000..31ea4754cf --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ProduceEndType.cs @@ -0,0 +1,9 @@ +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public enum ProduceEndType + { + SocketShutdownSend, + SocketDisconnect, + ConnectionKeepAlive, + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 531fc65858..4c3e4c8cc8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -3,19 +3,10 @@ using Microsoft.AspNet.Server.Kestrel.Networking; using System; -using System.Runtime.InteropServices; using System.Threading; namespace Microsoft.AspNet.Server.Kestrel.Http { - /// - /// Operations performed for buffered socket output - /// - public interface ISocketOutput - { - void Write(ArraySegment buffer, Action callback, object state); - } - public class SocketOutput : ISocketOutput { private readonly KestrelThread _thread; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index eb77481ed2..4a12712d0d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -4,7 +4,6 @@ using System; using System.Reflection; using System.Runtime.InteropServices; -using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index 8eeee2f719..b2e34c5aeb 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Reflection; using System.Runtime.InteropServices; -using System.Text; namespace Microsoft.AspNet.Server.Kestrel.Networking { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs index bc8addba09..138853da85 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvAsyncHandle.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking _uv.async_send(this); } - unsafe static void AsyncCb(IntPtr handle) + unsafe private static void AsyncCb(IntPtr handle) { FromIntPtr(handle)._callback.Invoke(); } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs new file mode 100644 index 0000000000..56e738710d --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvReq.cs @@ -0,0 +1,17 @@ +// 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. + +using System; + +namespace Microsoft.AspNet.Server.Kestrel.Networking +{ + public abstract class UvReq : UvMemory + { + protected override bool ReleaseHandle() + { + DestroyMemory(handle); + handle = IntPtr.Zero; + return true; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs similarity index 90% rename from src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs rename to src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 4696912db2..3e88312805 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -1,6 +1,3 @@ -// 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. - using System; using System.Collections.Generic; using System.Diagnostics; @@ -117,14 +114,4 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking } } } - - public abstract class UvReq : UvMemory - { - protected override bool ReleaseHandle() - { - DestroyMemory(handle); - handle = IntPtr.Zero; - return true; - } - } } \ No newline at end of file