Move non-nested classes and interfaces to their own files

This commit is contained in:
Stephen Halter 2015-06-23 15:15:13 -07:00
parent fd038b7b91
commit 4b66edc4fe
19 changed files with 155 additions and 133 deletions

View File

@ -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<UvStreamHandle, int, Exception, object> _readCallback = ReadCallback;

View File

@ -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; }
}
}

View File

@ -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<byte> data, Action<Exception, object> callback, object state);
}
public class Frame : FrameContext, IFrameControl
{
enum Mode

View File

@ -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; }
}
}

View File

@ -0,0 +1,9 @@
namespace Microsoft.AspNet.Server.Kestrel.Http
{
public interface IConnectionControl
{
void Pause();
void Resume();
void End(ProduceEndType endType);
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
public interface IFrameControl
{
void ProduceContinue();
void Write(ArraySegment<byte> data, Action<Exception, object> callback, object state);
}
}

View File

@ -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);
/// <summary>
/// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind
/// buffers to reduce number of array segments pinned
/// </summary>
/// <param name = "minimumSize">The smallest length of the ArraySegment.Count that may be returned</param>
/// <returns>An array segment which is a sub-block of a larger allocation</returns>
ArraySegment<byte> AllocSegment(int minimumSize);
/// <summary>
/// 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.
/// </summary>
/// <param name = "segment">The sub-block that was originally returned by a call to AllocSegment.</param>
void FreeSegment(ArraySegment<byte> segment);
}
}

View File

@ -0,0 +1,12 @@
using System;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
/// <summary>
/// Operations performed for buffered socket output
/// </summary>
public interface ISocketOutput
{
void Write(ArraySegment<byte> buffer, Action<Exception, object> callback, object state);
}
}

View File

@ -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<Frame, Task> Application { get; set; }
public IMemoryPool Memory { get; set; }
}
/// <summary>
/// Summary description for Accept
/// </summary>

View File

@ -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<Frame, Task> Application { get; set; }
public IMemoryPool Memory { get; set; }
}
}

View File

@ -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);
/// <summary>
/// Acquires a sub-segment of a larger memory allocation. Used for async sends of write-behind
/// buffers to reduce number of array segments pinned
/// </summary>
/// <param name = "minimumSize">The smallest length of the ArraySegment.Count that may be returned</param>
/// <returns>An array segment which is a sub-block of a larger allocation</returns>
ArraySegment<byte> AllocSegment(int minimumSize);
/// <summary>
/// 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.
/// </summary>
/// <param name = "segment">The sub-block that was originally returned by a call to AllocSegment.</param>
void FreeSegment(ArraySegment<byte> segment);
}
public class MemoryPool : IMemoryPool
{
static readonly byte[] EmptyArray = new byte[0];

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
namespace Microsoft.AspNet.Server.Kestrel.Http
{

View File

@ -0,0 +1,9 @@
namespace Microsoft.AspNet.Server.Kestrel.Http
{
public enum ProduceEndType
{
SocketShutdownSend,
SocketDisconnect,
ConnectionKeepAlive,
}
}

View File

@ -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
{
/// <summary>
/// Operations performed for buffered socket output
/// </summary>
public interface ISocketOutput
{
void Write(ArraySegment<byte> buffer, Action<Exception, object> callback, object state);
}
public class SocketOutput : ISocketOutput
{
private readonly KestrelThread _thread;

View File

@ -4,7 +4,6 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{

View File

@ -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
{

View File

@ -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<UvAsyncHandle>(handle)._callback.Invoke();
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}