Adding core clr configurations
This commit is contained in:
parent
ad738561af
commit
660babcd7f
|
|
@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
var self = (Connection)x;
|
var self = (Connection)x;
|
||||||
var shutdown = new UvShutdownReq();
|
var shutdown = new UvShutdownReq();
|
||||||
shutdown.Init(self.Thread.Loop);
|
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);
|
this);
|
||||||
break;
|
break;
|
||||||
|
|
@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
break;
|
break;
|
||||||
case ProduceEndType.SocketDisconnect:
|
case ProduceEndType.SocketDisconnect:
|
||||||
Thread.Post(
|
Thread.Post(
|
||||||
x => ((UvHandle)x).Close(),
|
x => ((UvHandle)x).Dispose(),
|
||||||
_socket);
|
_socket);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -454,7 +454,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
|
|
||||||
static string GetString(ArraySegment<byte> range, int startIndex, int endIndex)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
|
|
@ -17,11 +19,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
_responseStream = responseStream;
|
_responseStream = responseStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET45
|
||||||
public override void Close()
|
public override void Close()
|
||||||
{
|
{
|
||||||
_requestStream.Close();
|
_requestStream.Close();
|
||||||
_responseStream.Close();
|
_responseStream.Close();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
|
@ -37,6 +41,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
_responseStream.Flush();
|
_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)
|
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||||
{
|
{
|
||||||
return _requestStream.BeginRead(buffer, offset, count, callback, state);
|
return _requestStream.BeginRead(buffer, offset, count, callback, state);
|
||||||
|
|
@ -46,7 +56,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
return _requestStream.EndRead(asyncResult);
|
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)
|
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||||
{
|
{
|
||||||
return _responseStream.BeginWrite(buffer, offset, count, callback, state);
|
return _responseStream.BeginWrite(buffer, offset, count, callback, state);
|
||||||
|
|
@ -56,6 +78,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
_responseStream.EndWrite(asyncResult);
|
_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)
|
public override long Seek(long offset, SeekOrigin origin)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
return ReadAsync(buffer, offset, count).Result;
|
return ReadAsync(buffer, offset, count).Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NET45
|
||||||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||||
{
|
{
|
||||||
var task = ReadAsync(buffer, offset, count, CancellationToken.None, 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;
|
return ((Task<int>)asyncResult).Result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
|
|
||||||
private void OnDispose(object listenSocket)
|
private void OnDispose(object listenSocket)
|
||||||
{
|
{
|
||||||
((UvHandle)listenSocket).Close();
|
((UvHandle)listenSocket).Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,14 +36,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
_memory = memory;
|
_memory = memory;
|
||||||
_textArray = _memory.AllocChar(_textLength);
|
_textArray = _memory.AllocChar(_textLength);
|
||||||
_dataArray = _memory.Empty;
|
_dataArray = _memory.Empty;
|
||||||
_encoder = Encoding.Default.GetEncoder();
|
_encoder = Encoding.UTF8.GetEncoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Encoding Encoding
|
public override Encoding Encoding
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return Encoding.Default;
|
return Encoding.UTF8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
_pin.Free();
|
_pin.Free();
|
||||||
//NOTE: pool this?
|
//NOTE: pool this?
|
||||||
Close();
|
Dispose();
|
||||||
_callback(_state);
|
_callback(_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,14 @@ namespace Microsoft.AspNet.Server.Kestrel
|
||||||
public void Stop(TimeSpan timeout)
|
public void Stop(TimeSpan timeout)
|
||||||
{
|
{
|
||||||
Post(OnStop, null);
|
Post(OnStop, null);
|
||||||
if (!_thread.Join(timeout))
|
if (!_thread.Join((int)timeout.TotalMilliseconds))
|
||||||
{
|
{
|
||||||
Post(OnStopImmediate, null);
|
Post(OnStopImmediate, null);
|
||||||
if (!_thread.Join(timeout))
|
if (!_thread.Join((int)timeout.TotalMilliseconds))
|
||||||
{
|
{
|
||||||
|
#if NET45
|
||||||
_thread.Abort();
|
_thread.Abort();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_closeError != null)
|
if (_closeError != null)
|
||||||
|
|
@ -107,7 +109,7 @@ namespace Microsoft.AspNet.Server.Kestrel
|
||||||
var ran2 = _loop.Run();
|
var ran2 = _loop.Run();
|
||||||
|
|
||||||
// delete the last of the unmanaged memory
|
// delete the last of the unmanaged memory
|
||||||
_loop.Close();
|
_loop.Dispose();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
||||||
public class UvAsyncHandle : UvHandle
|
public class UvAsyncHandle : UvHandle
|
||||||
{
|
{
|
||||||
private static Libuv.uv_async_cb _uv_async_cb = AsyncCb;
|
private static Libuv.uv_async_cb _uv_async_cb = AsyncCb;
|
||||||
|
|
||||||
unsafe static void AsyncCb(IntPtr handle)
|
|
||||||
{
|
|
||||||
FromIntPtr<UvAsyncHandle>(handle)._callback.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Action _callback;
|
private Action _callback;
|
||||||
|
|
||||||
public void Init(UvLoopHandle loop, Action callback)
|
public void Init(UvLoopHandle loop, Action callback)
|
||||||
|
|
@ -25,18 +19,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
||||||
|
|
||||||
public void DangerousClose()
|
public void DangerousClose()
|
||||||
{
|
{
|
||||||
Close();
|
Dispose();
|
||||||
ReleaseHandle();
|
ReleaseHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UvAsyncCb(IntPtr handle)
|
|
||||||
{
|
|
||||||
_callback.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Send()
|
public void Send()
|
||||||
{
|
{
|
||||||
_uv.async_send(this);
|
_uv.async_send(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe static void AsyncCb(IntPtr handle)
|
||||||
|
{
|
||||||
|
FromIntPtr<UvAsyncHandle>(handle)._callback.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
||||||
_threadId = loop._threadId;
|
_threadId = loop._threadId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Validate(bool closed = false)
|
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(!IsInvalid, "Handle is invalid");
|
||||||
Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is correct");
|
Trace.Assert(_threadId == Thread.CurrentThread.ManagedThreadId, "ThreadId is correct");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,19 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.Hosting": "0.1-*"
|
"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": {
|
"compilationOptions": {
|
||||||
"allowUnsafe": true
|
"allowUnsafe": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@ Hello World");
|
||||||
engine.Stop();
|
engine.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Skip = "This is still not working")]
|
[Fact]
|
||||||
public async Task Expect100ContinueForBody()
|
public async Task Expect100ContinueForBody()
|
||||||
{
|
{
|
||||||
var engine = new KestrelEngine();
|
var engine = new KestrelEngine();
|
||||||
|
|
@ -265,10 +265,20 @@ Hello World");
|
||||||
|
|
||||||
using (var connection = new TestConnection())
|
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.Receive("HTTP/1.1 100 Continue", "\r\n");
|
||||||
await connection.SendEnd("Hello World");
|
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();
|
started.Dispose();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
var loop = new UvLoopHandle();
|
var loop = new UvLoopHandle();
|
||||||
loop.Init(_uv);
|
loop.Init(_uv);
|
||||||
loop.Run();
|
loop.Run();
|
||||||
loop.Close();
|
loop.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -42,11 +42,11 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
trigger.Init(loop, () =>
|
trigger.Init(loop, () =>
|
||||||
{
|
{
|
||||||
called = true;
|
called = true;
|
||||||
trigger.Close();
|
trigger.Dispose();
|
||||||
});
|
});
|
||||||
trigger.Send();
|
trigger.Send();
|
||||||
loop.Run();
|
loop.Run();
|
||||||
loop.Close();
|
loop.Dispose();
|
||||||
Assert.True(called);
|
Assert.True(called);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,9 +58,9 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
var tcp = new UvTcpHandle();
|
var tcp = new UvTcpHandle();
|
||||||
tcp.Init(loop);
|
tcp.Init(loop);
|
||||||
tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||||
tcp.Close();
|
tcp.Dispose();
|
||||||
loop.Run();
|
loop.Run();
|
||||||
loop.Close();
|
loop.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -77,8 +77,8 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
var tcp2 = new UvTcpHandle();
|
var tcp2 = new UvTcpHandle();
|
||||||
tcp2.Init(loop);
|
tcp2.Init(loop);
|
||||||
stream.Accept(tcp2);
|
stream.Accept(tcp2);
|
||||||
tcp2.Close();
|
tcp2.Dispose();
|
||||||
stream.Close();
|
stream.Dispose();
|
||||||
}, null);
|
}, null);
|
||||||
var t = Task.Run(async () =>
|
var t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
|
@ -92,10 +92,10 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
new IPEndPoint(IPAddress.Loopback, 54321),
|
new IPEndPoint(IPAddress.Loopback, 54321),
|
||||||
null,
|
null,
|
||||||
TaskCreationOptions.None);
|
TaskCreationOptions.None);
|
||||||
socket.Close();
|
socket.Dispose();
|
||||||
});
|
});
|
||||||
loop.Run();
|
loop.Run();
|
||||||
loop.Close();
|
loop.Dispose();
|
||||||
await t;
|
await t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,11 +122,11 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
bytesRead += nread;
|
bytesRead += nread;
|
||||||
if (nread == 0)
|
if (nread == 0)
|
||||||
{
|
{
|
||||||
tcp2.Close();
|
tcp2.Dispose();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
null);
|
null);
|
||||||
tcp.Close();
|
tcp.Dispose();
|
||||||
}, null);
|
}, null);
|
||||||
var t = Task.Run(async () =>
|
var t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
|
@ -147,10 +147,10 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
SocketFlags.None,
|
SocketFlags.None,
|
||||||
null,
|
null,
|
||||||
TaskCreationOptions.None);
|
TaskCreationOptions.None);
|
||||||
socket.Close();
|
socket.Dispose();
|
||||||
});
|
});
|
||||||
loop.Run();
|
loop.Run();
|
||||||
loop.Close();
|
loop.Dispose();
|
||||||
await t;
|
await t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_stream.Close();
|
_stream.Dispose();
|
||||||
_socket.Close();
|
_socket.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Send(params string[] lines)
|
public async Task Send(params string[] lines)
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.KestralTests
|
||||||
while (offset < expected.Length)
|
while (offset < expected.Length)
|
||||||
{
|
{
|
||||||
var task = _reader.ReadAsync(actual, offset, actual.Length - offset);
|
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;
|
var count = await task;
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,17 @@
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"net45": {
|
"net45": {
|
||||||
"compilationOptions": { "define": [ "TRACE" ] }
|
"compilationOptions": { "define": [ "TRACE" ] }
|
||||||
|
},
|
||||||
|
"k10": {
|
||||||
|
"compilationOptions": { "define": [ "TRACE" ] },
|
||||||
|
"dependencies": {
|
||||||
|
"System.Net.Sockets": "4.0.0.0",
|
||||||
|
"System.Runtime.Handles": "4.0.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
"run": "Xunit.KRunner",
|
"run": "Xunit.KRunner -trait x=vs",
|
||||||
"test": "Xunit.KRunner"
|
"test": "Xunit.KRunner"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue