Adding core clr configurations

This commit is contained in:
Louis DeJardin 2014-06-10 00:28:52 -07:00
parent ad738561af
commit 660babcd7f
16 changed files with 101 additions and 43 deletions

View File

@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
var self = (Connection)x;
var shutdown = new UvShutdownReq();
shutdown.Init(self.Thread.Loop);
shutdown.Shutdown(self._socket, (req, status, state) => req.Close(), null);
shutdown.Shutdown(self._socket, (req, status, state) => req.Dispose(), null);
},
this);
break;
@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
break;
case ProduceEndType.SocketDisconnect:
Thread.Post(
x => ((UvHandle)x).Close(),
x => ((UvHandle)x).Dispose(),
_socket);
break;
}

View File

@ -454,7 +454,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
static string GetString(ArraySegment<byte> range, int startIndex, int endIndex)
{
return Encoding.Default.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex);
return Encoding.UTF8.GetString(range.Array, range.Offset + startIndex, endIndex - startIndex);
}

View File

@ -3,6 +3,8 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@ -17,11 +19,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
_responseStream = responseStream;
}
#if NET45
public override void Close()
{
_requestStream.Close();
_responseStream.Close();
}
#endif
protected override void Dispose(bool disposing)
{
@ -37,6 +41,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
_responseStream.Flush();
}
public override Task FlushAsync(CancellationToken cancellationToken)
{
return _responseStream.FlushAsync(cancellationToken);
}
#if NET45
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _requestStream.BeginRead(buffer, offset, count, callback, state);
@ -46,7 +56,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
return _requestStream.EndRead(asyncResult);
}
#endif
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _requestStream.ReadAsync(buffer, offset, count, cancellationToken);
}
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
return _requestStream.CopyToAsync(destination, bufferSize, cancellationToken);
}
#if NET45
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _responseStream.BeginWrite(buffer, offset, count, callback, state);
@ -56,6 +78,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
_responseStream.EndWrite(asyncResult);
}
#endif
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _responseStream.WriteAsync(buffer, offset, count, cancellationToken);
}
public override long Seek(long offset, SeekOrigin origin)
{

View File

@ -41,6 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return ReadAsync(buffer, offset, count).Result;
}
#if NET45
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
var task = ReadAsync(buffer, offset, count, CancellationToken.None, state);
@ -55,6 +56,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
return ((Task<int>)asyncResult).Result;
}
#endif
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{

View File

@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private void OnDispose(object listenSocket)
{
((UvHandle)listenSocket).Close();
((UvHandle)listenSocket).Dispose();
}
}
}

View File

@ -36,14 +36,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
_memory = memory;
_textArray = _memory.AllocChar(_textLength);
_dataArray = _memory.Empty;
_encoder = Encoding.Default.GetEncoder();
_encoder = Encoding.UTF8.GetEncoder();
}
public override Encoding Encoding
{
get
{
return Encoding.Default;
return Encoding.UTF8;
}
}

View File

@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
_pin.Free();
//NOTE: pool this?
Close();
Dispose();
_callback(_state);
}
}

View File

@ -45,12 +45,14 @@ namespace Microsoft.AspNet.Server.Kestrel
public void Stop(TimeSpan timeout)
{
Post(OnStop, null);
if (!_thread.Join(timeout))
if (!_thread.Join((int)timeout.TotalMilliseconds))
{
Post(OnStopImmediate, null);
if (!_thread.Join(timeout))
if (!_thread.Join((int)timeout.TotalMilliseconds))
{
#if NET45
_thread.Abort();
#endif
}
}
if (_closeError != null)
@ -107,7 +109,7 @@ namespace Microsoft.AspNet.Server.Kestrel
var ran2 = _loop.Run();
// delete the last of the unmanaged memory
_loop.Close();
_loop.Dispose();
}
catch (Exception ex)
{

View File

@ -8,12 +8,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
public class UvAsyncHandle : UvHandle
{
private static Libuv.uv_async_cb _uv_async_cb = AsyncCb;
unsafe static void AsyncCb(IntPtr handle)
{
FromIntPtr<UvAsyncHandle>(handle)._callback.Invoke();
}
private Action _callback;
public void Init(UvLoopHandle loop, Action callback)
@ -25,18 +19,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
public void DangerousClose()
{
Close();
Dispose();
ReleaseHandle();
}
private void UvAsyncCb(IntPtr handle)
{
_callback.Invoke();
}
public void Send()
{
_uv.async_send(this);
}
unsafe static void AsyncCb(IntPtr handle)
{
FromIntPtr<UvAsyncHandle>(handle)._callback.Invoke();
}
}
}

View File

@ -45,9 +45,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
_threadId = loop._threadId;
}
public void Validate(bool closed = false)
{
Trace.Assert(IsClosed == closed, "Handle is closed");
Trace.Assert(closed || !IsClosed, "Handle is closed");
Trace.Assert(!IsInvalid, "Handle is invalid");
Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is correct");
}

View File

@ -3,6 +3,19 @@
"dependencies": {
"Microsoft.AspNet.Hosting": "0.1-*"
},
"configurations": {
"net45": { },
"k10": {
"dependencies": {
"System.Threading.ThreadPool": "4.0.10.0",
"System.Diagnostics.Debug": "4.0.10.0",
"System.Threading.Thread": "4.0.0.0",
"System.Diagnostics.TraceSource": "4.0.0.0",
"System.Text.Encoding": "4.0.20.0",
"System.Threading.Tasks": "4.0.10.0"
}
}
},
"compilationOptions": {
"allowUnsafe": true
}

View File

@ -256,7 +256,7 @@ Hello World");
engine.Stop();
}
[Fact(Skip = "This is still not working")]
[Fact]
public async Task Expect100ContinueForBody()
{
var engine = new KestrelEngine();
@ -265,10 +265,20 @@ Hello World");
using (var connection = new TestConnection())
{
await connection.Send("POST / HTTP/1.1", "Expect: 100-continue", "Content-Length: 11", "\r\n");
await connection.Send(
"POST / HTTP/1.1",
"Expect: 100-continue",
"Content-Length: 11",
"Connection: close",
"\r\n");
await connection.Receive("HTTP/1.1 100 Continue", "\r\n");
await connection.SendEnd("Hello World");
await connection.ReceiveEnd("HTTP/1.1 200 OK", "Content-Length: 11", "", "Hello World");
await connection.Receive(
"HTTP/1.1 200 OK",
"Content-Length: 11",
"Connection: close",
"",
"Hello World");
}
started.Dispose();

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Server.KestralTests
var loop = new UvLoopHandle();
loop.Init(_uv);
loop.Run();
loop.Close();
loop.Dispose();
}
[Fact]
@ -42,11 +42,11 @@ namespace Microsoft.AspNet.Server.KestralTests
trigger.Init(loop, () =>
{
called = true;
trigger.Close();
trigger.Dispose();
});
trigger.Send();
loop.Run();
loop.Close();
loop.Dispose();
Assert.True(called);
}
@ -58,9 +58,9 @@ namespace Microsoft.AspNet.Server.KestralTests
var tcp = new UvTcpHandle();
tcp.Init(loop);
tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0));
tcp.Close();
tcp.Dispose();
loop.Run();
loop.Close();
loop.Dispose();
}
@ -77,8 +77,8 @@ namespace Microsoft.AspNet.Server.KestralTests
var tcp2 = new UvTcpHandle();
tcp2.Init(loop);
stream.Accept(tcp2);
tcp2.Close();
stream.Close();
tcp2.Dispose();
stream.Dispose();
}, null);
var t = Task.Run(async () =>
{
@ -92,10 +92,10 @@ namespace Microsoft.AspNet.Server.KestralTests
new IPEndPoint(IPAddress.Loopback, 54321),
null,
TaskCreationOptions.None);
socket.Close();
socket.Dispose();
});
loop.Run();
loop.Close();
loop.Dispose();
await t;
}
@ -122,11 +122,11 @@ namespace Microsoft.AspNet.Server.KestralTests
bytesRead += nread;
if (nread == 0)
{
tcp2.Close();
tcp2.Dispose();
}
},
null);
tcp.Close();
tcp.Dispose();
}, null);
var t = Task.Run(async () =>
{
@ -147,10 +147,10 @@ namespace Microsoft.AspNet.Server.KestralTests
SocketFlags.None,
null,
TaskCreationOptions.None);
socket.Close();
socket.Dispose();
});
loop.Run();
loop.Close();
loop.Dispose();
await t;
}
}

View File

@ -32,8 +32,8 @@ namespace Microsoft.AspNet.Server.KestralTests
}
public void Dispose()
{
_stream.Close();
_socket.Close();
_stream.Dispose();
_socket.Dispose();
}
public async Task Send(params string[] lines)
@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.KestralTests
while (offset < expected.Length)
{
var task = _reader.ReadAsync(actual, offset, actual.Length - offset);
Assert.True(task.Wait(1000), "timeout");
// Assert.True(task.Wait(1000), "timeout");
var count = await task;
if (count == 0)
{

View File

@ -9,10 +9,17 @@
"configurations": {
"net45": {
"compilationOptions": { "define": [ "TRACE" ] }
},
"k10": {
"compilationOptions": { "define": [ "TRACE" ] },
"dependencies": {
"System.Net.Sockets": "4.0.0.0",
"System.Runtime.Handles": "4.0.0.0"
}
}
},
"commands": {
"run": "Xunit.KRunner",
"run": "Xunit.KRunner -trait x=vs",
"test": "Xunit.KRunner"
}
}