Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Move non-nested classes and interfaces to their own files #112

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion samples/SampleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// 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 SampleApp
{
Expand Down
15 changes: 9 additions & 6 deletions samples/SampleApp/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// 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 Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;

Expand All @@ -10,11 +13,11 @@ public void Configure(IApplicationBuilder app)
{
app.Run(async context =>
{
Console.WriteLine("{0} {1}{2}{3}",
context.Request.Method,
context.Request.PathBase,
context.Request.Path,
context.Request.QueryString);
//Console.WriteLine("{0} {1}{2}{3}",
// context.Request.Method,
// context.Request.PathBase,
// context.Request.Path,
// context.Request.QueryString);

context.Response.ContentLength = 11;
context.Response.ContentType = "text/plain";
Expand Down
8 changes: 2 additions & 6 deletions samples/SampleApp/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
"Kestrel": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Console": "4.0.0-beta-*"
}
}
"dnx451": { }

},
"commands": {
"run": "Kestrel",
Expand Down
5 changes: 4 additions & 1 deletion src/Kestrel/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// 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.Linq;

namespace Kestrel
Expand Down
5 changes: 4 additions & 1 deletion src/Kestrel/ServerAddress.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Kestrel
// 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 Kestrel
{
public class ServerAddress
{
Expand Down
5 changes: 0 additions & 5 deletions src/Kestrel/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
"frameworks": {
"dnx451": {
"dependencies": { }
},
"dnxcore50": {
"dependencies": {
"System.Runtime": "4.0.20-beta-*"
}
}
}
}
31 changes: 0 additions & 31 deletions src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/Microsoft.AspNet.Server.Kestrel/Http/ConnectionContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.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; }
}
}
34 changes: 4 additions & 30 deletions src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,13 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

// ReSharper disable AccessToModifiedClosure

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
Expand Down Expand Up @@ -187,7 +159,9 @@ private void Execute()
ResponseBody = new FrameResponseStream(this);
DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody);
SocketInput.Free();
Task.Run(ExecuteAsync);
//Task.Run(ExecuteAsync);
//var ignore = ExecuteAsync();
ThreadPool.UnsafeQueueUserWorkItem(_ => ExecuteAsync(), null);
}

public void OnStarting(Func<object, Task> callback, object state)
Expand Down
20 changes: 20 additions & 0 deletions src/Microsoft.AspNet.Server.Kestrel/Http/FrameContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.AspNet.Server.Kestrel.Http
{
public class FrameContext : ConnectionContext
{
public FrameContext()
{

}

public FrameContext(ConnectionContext context) : base(context)
{

}

public IFrameControl FrameControl { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/Microsoft.AspNet.Server.Kestrel/Http/IConnectionControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.AspNet.Server.Kestrel.Http
{
public interface IConnectionControl
{
void Pause();
void Resume();
void End(ProduceEndType endType);
}
}
13 changes: 13 additions & 0 deletions src/Microsoft.AspNet.Server.Kestrel/Http/IFrameControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.Http
{
public interface IFrameControl
{
void ProduceContinue();
void Write(ArraySegment<byte> data, Action<Exception, object> callback, object state);
}
}
35 changes: 35 additions & 0 deletions src/Microsoft.AspNet.Server.Kestrel/Http/IMemoryPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.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);
}
}
15 changes: 15 additions & 0 deletions src/Microsoft.AspNet.Server.Kestrel/Http/ISocketOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.Http
{
/// <summary>
/// Operations performed for buffered socket output
/// </summary>
public interface ISocketOutput
{
void Write(ArraySegment<byte> buffer, Action<Exception, object> callback, object state);
}
}
18 changes: 0 additions & 18 deletions src/Microsoft.AspNet.Server.Kestrel/Http/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@

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>
Expand Down
26 changes: 26 additions & 0 deletions src/Microsoft.AspNet.Server.Kestrel/Http/ListenerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.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; }
}
}
28 changes: 0 additions & 28 deletions src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,6 @@

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];
Expand Down
Loading