Replace Trace.WriteLine with ITraceLogger

This commit is contained in:
Ivan Derevyanko 2015-09-09 00:26:26 +02:00
parent ed4850a2b1
commit a93a66fe7c
28 changed files with 162 additions and 102 deletions

View File

@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using Microsoft.AspNet.Server.Kestrel.Networking;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
if (errorDone && error != null)
{
Trace.WriteLine("Connection.OnRead " + error.ToString());
Log.LogError("Connection.OnRead", error);
}
}
@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
catch (Exception ex)
{
Trace.WriteLine("Connection._frame.Consume " + ex.ToString());
Log.LogError("Connection._frame.Consume ", ex);
}
}
@ -121,7 +121,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
Log.ConnectionWriteFin(_connectionId, 1);
var self = (Connection)state;
var shutdown = new UvShutdownReq();
var shutdown = new UvShutdownReq(Log);
shutdown.Init(self.Thread.Loop);
shutdown.Shutdown(self._socket, (req, status, _) =>
{

View File

@ -3,11 +3,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Framework.Logging;
using Microsoft.Framework.Primitives;
// ReSharper disable AccessToModifiedClosure
@ -276,7 +276,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
Trace.WriteLine("WriteChunkPrefix" + error.ToString());
Log.LogError("WriteChunkPrefix", error);
}
},
null,
@ -290,7 +290,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
Trace.WriteLine("WriteChunkSuffix" + error.ToString());
Log.LogError("WriteChunkSuffix", error);
}
},
null,
@ -304,7 +304,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
Trace.WriteLine("WriteChunkedResponseSuffix" + error.ToString());
Log.LogError("WriteChunkedResponseSuffix", error);
}
},
null,
@ -338,7 +338,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
Trace.WriteLine("ProduceContinue " + error.ToString());
Log.LogError("ProduceContinue ", error);
}
},
null);
@ -361,7 +361,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
if (error != null)
{
Trace.WriteLine("ProduceStart " + error.ToString());
Log.LogError("ProduceStart ", error);
}
((IDisposable)state).Dispose();
},

View File

@ -3,8 +3,8 @@
using Microsoft.AspNet.Server.Kestrel.Networking;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@ -50,11 +50,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// </summary>
protected abstract UvStreamHandle CreateListenSocket(string host, int port);
protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state)
protected void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state)
{
if (error != null)
{
Trace.WriteLine("Listener.ConnectionCallback " + error.ToString());
Log.LogError("Listener.ConnectionCallback ", error);
}
else
{

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
await Thread.PostAsync(_ =>
{
ListenPipe = new UvPipeHandle();
ListenPipe = new UvPipeHandle(Log);
ListenPipe.Init(Thread.Loop, false);
ListenPipe.Bind(pipeName);
ListenPipe.Listen(Constants.ListenBacklog, OnListenPipe, null);
@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return;
}
var dispatchPipe = new UvPipeHandle();
var dispatchPipe = new UvPipeHandle(Log);
dispatchPipe.Init(Thread.Loop, true);
try
{
@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
else
{
var dispatchPipe = _dispatchPipes[index];
var write = new UvWriteReq();
var write = new UvWriteReq(Log);
write.Init(Thread.Loop);
write.Write2(
dispatchPipe,

View File

@ -3,9 +3,9 @@
using Microsoft.AspNet.Server.Kestrel.Networking;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Http
{
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Thread = thread;
Application = application;
DispatchPipe = new UvPipeHandle();
DispatchPipe = new UvPipeHandle(Log);
var tcs = new TaskCompletionSource<int>();
Thread.Post(_ =>
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
try
{
DispatchPipe.Init(Thread.Loop, true);
var connect = new UvConnectRequest();
var connect = new UvConnectRequest(Log);
connect.Init(Thread.Loop);
connect.Connect(
DispatchPipe,
@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
catch (Exception ex)
{
Trace.WriteLine("DispatchPipe.Accept " + ex.Message);
Log.LogError("DispatchPipe.Accept", ex);
acceptSocket.Dispose();
return;
}

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// </summary>
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
var socket = new UvPipeHandle();
var socket = new UvPipeHandle(Log);
socket.Init(Thread.Loop, false);
socket.Bind(host);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// <param name="status">Connection status</param>
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
var acceptSocket = new UvPipeHandle();
var acceptSocket = new UvPipeHandle(Log);
acceptSocket.Init(Thread.Loop, false);
listenSocket.Accept(acceptSocket);

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// </summary>
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
var socket = new UvPipeHandle();
var socket = new UvPipeHandle(Log);
socket.Init(Thread.Loop, false);
socket.Bind(host);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// <param name="status">Connection status</param>
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
var acceptSocket = new UvPipeHandle();
var acceptSocket = new UvPipeHandle(Log);
acceptSocket.Init(Thread.Loop, false);
listenSocket.Accept(acceptSocket);

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// </summary>
protected override UvStreamHandle CreateAcceptSocket()
{
var acceptSocket = new UvPipeHandle();
var acceptSocket = new UvPipeHandle(Log);
acceptSocket.Init(Thread.Loop, false);
return acceptSocket;
}

View File

@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
buffers[i++] = buffer;
}
var writeReq = new UvWriteReq();
var writeReq = new UvWriteReq(_log);
writeReq.Init(_thread.Loop);
writeReq.Write(_socket, new ArraySegment<ArraySegment<byte>>(buffers), (r, status, error, state) =>

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// </summary>
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
var socket = new UvTcpHandle();
var socket = new UvTcpHandle(Log);
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
socket.Bind(new IPEndPoint(IPAddress.Any, port));
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// <param name="status">Connection status</param>
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
var acceptSocket = new UvTcpHandle();
var acceptSocket = new UvTcpHandle(Log);
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
listenSocket.Accept(acceptSocket);

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// </summary>
protected override UvStreamHandle CreateListenSocket(string host, int port)
{
var socket = new UvTcpHandle();
var socket = new UvTcpHandle(Log);
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
socket.Bind(new IPEndPoint(IPAddress.Any, port));
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// <param name="status">Connection status</param>
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
var acceptSocket = new UvTcpHandle();
var acceptSocket = new UvTcpHandle(Log);
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
listenSocket.Accept(acceptSocket);

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// </summary>
protected override UvStreamHandle CreateAcceptSocket()
{
var acceptSocket = new UvTcpHandle();
var acceptSocket = new UvTcpHandle(Log);
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
return acceptSocket;
}

View File

@ -4,11 +4,12 @@
using Microsoft.AspNet.Server.Kestrel.Networking;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel
{
@ -30,13 +31,15 @@ namespace Microsoft.AspNet.Server.Kestrel
private object _workSync = new Object();
private bool _stopImmediate = false;
private ExceptionDispatchInfo _closeError;
private IKestrelTrace _log;
public KestrelThread(KestrelEngine engine, ServiceContext serviceContext)
{
_engine = engine;
_appShutdown = serviceContext.AppShutdown;
_loop = new UvLoopHandle();
_post = new UvAsyncHandle();
_log = serviceContext.Log;
_loop = new UvLoopHandle(_log);
_post = new UvAsyncHandle(_log);
_thread = new Thread(ThreadStart);
QueueCloseHandle = PostCloseHandle;
}
@ -272,7 +275,7 @@ namespace Microsoft.AspNet.Server.Kestrel
}
else
{
Trace.WriteLine("KestrelThread.DoPostWork " + ex.ToString());
_log.LogError("KestrelThread.DoPostWork", ex);
}
}
}
@ -295,7 +298,7 @@ namespace Microsoft.AspNet.Server.Kestrel
}
catch (Exception ex)
{
Trace.WriteLine("KestrelThread.DoPostCloseHandle " + ex.ToString());
_log.LogError("KestrelThread.DoPostCloseHandle", ex);
}
}
}

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
@ -10,6 +11,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
private static Libuv.uv_async_cb _uv_async_cb = AsyncCb;
private Action _callback;
public UvAsyncHandle(IKestrelTrace logger) : base(logger)
{
}
public void Init(UvLoopHandle loop, Action callback)
{
CreateMemory(

View File

@ -2,9 +2,8 @@
// 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;
using System.Runtime.InteropServices;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
@ -13,11 +12,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
/// </summary>
public class UvConnectRequest : UvRequest
{
private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb;
private readonly Libuv.uv_connect_cb _uv_connect_cb;
private Action<UvConnectRequest, int, Exception, object> _callback;
private object _state;
public UvConnectRequest(IKestrelTrace logger) : base (logger)
{
_uv_connect_cb = UvConnectCb;
}
public void Init(UvLoopHandle loop)
{
var requestSize = loop.Libuv.req_size(Libuv.RequestType.CONNECT);
@ -40,7 +44,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
Libuv.pipe_connect(this, pipe, name, _uv_connect_cb);
}
private static void UvConnectCb(IntPtr ptr, int status)
private void UvConnectCb(IntPtr ptr, int status)
{
var req = FromIntPtr<UvConnectRequest>(ptr);
req.Unpin();
@ -63,7 +67,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
}
catch (Exception ex)
{
Trace.WriteLine("UvConnectRequest " + ex.ToString());
_log.LogError("UvConnectRequest", ex);
}
}
}

View File

@ -3,6 +3,7 @@
using System;
using System.Threading;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
@ -11,6 +12,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
private static Libuv.uv_close_cb _destroyMemory = DestroyMemory;
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;
protected UvHandle(IKestrelTrace logger) : base (logger)
{
}
unsafe protected void CreateHandle(
Libuv uv,
int threadId,

View File

@ -3,11 +3,16 @@
using System;
using System.Threading;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
public class UvLoopHandle : UvHandle
{
public UvLoopHandle(IKestrelTrace logger) : base(logger)
{
}
public void Init(Libuv uv)
{
CreateMemory(

View File

@ -5,6 +5,7 @@ using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
@ -15,9 +16,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{
protected Libuv _uv;
protected int _threadId;
protected IKestrelTrace _log;
public UvMemory() : base(IntPtr.Zero, true)
protected UvMemory(IKestrelTrace logger) : base(IntPtr.Zero, true)
{
_log = logger;
}
public Libuv Libuv { get { return _uv; } }

View File

@ -3,11 +3,16 @@
using System;
using System.Net;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
public class UvPipeHandle : UvStreamHandle
{
public UvPipeHandle(IKestrelTrace logger) : base(logger)
{
}
public void Init(UvLoopHandle loop, bool ipc)
{
CreateMemory(

View File

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
@ -10,6 +8,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{
private GCHandle _pin;
protected UvRequest(IKestrelTrace logger) : base (logger)
{
}
protected override bool ReleaseHandle()
{
DestroyMemory(handle);

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Runtime.InteropServices;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
@ -16,6 +16,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
private Action<UvShutdownReq, int, object> _callback;
private object _state;
public UvShutdownReq(IKestrelTrace logger) : base (logger)
{
}
public void Init(UvLoopHandle loop)
{
CreateMemory(

View File

@ -2,16 +2,17 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
public abstract class UvStreamHandle : UvHandle
{
private readonly static Libuv.uv_connection_cb _uv_connection_cb = UvConnectionCb;
private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb;
private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb;
private readonly Libuv.uv_connection_cb _uv_connection_cb;
private readonly Libuv.uv_alloc_cb _uv_alloc_cb;
private readonly Libuv.uv_read_cb _uv_read_cb;
public Action<UvStreamHandle, int, Exception, object> _listenCallback;
public object _listenState;
@ -22,6 +23,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
public object _readState;
private GCHandle _readVitality;
protected UvStreamHandle(IKestrelTrace logger) : base(logger)
{
_uv_connection_cb = UvConnectionCb;
_uv_alloc_cb = UvAllocCb;
_uv_read_cb = UvReadCb;
}
protected override bool ReleaseHandle()
{
if (_listenVitality.IsAllocated)
@ -114,7 +122,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
}
private static void UvConnectionCb(IntPtr handle, int status)
private void UvConnectionCb(IntPtr handle, int status)
{
var stream = FromIntPtr<UvStreamHandle>(handle);
@ -127,12 +135,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
}
catch (Exception ex)
{
Trace.WriteLine("UvConnectionCb " + ex.ToString());
_log.LogError("UvConnectionCb", ex);
}
}
private static void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf)
private void UvAllocCb(IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf)
{
var stream = FromIntPtr<UvStreamHandle>(handle);
try
@ -141,13 +149,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
}
catch (Exception ex)
{
Trace.WriteLine("UvAllocCb " + ex.ToString());
_log.LogError("UvAllocCb", ex);
buf = stream.Libuv.buf_init(IntPtr.Zero, 0);
throw;
}
}
private static void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf)
private void UvReadCb(IntPtr handle, int nread, ref Libuv.uv_buf_t buf)
{
var stream = FromIntPtr<UvStreamHandle>(handle);
@ -166,7 +174,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
}
catch (Exception ex)
{
Trace.WriteLine("UbReadCb " + ex.ToString());
_log.LogError("UbReadCb", ex);
}
}

View File

@ -3,11 +3,16 @@
using System;
using System.Net;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
public class UvTcpHandle : UvStreamHandle
{
public UvTcpHandle(IKestrelTrace logger) : base(logger)
{
}
public void Init(UvLoopHandle loop)
{
CreateMemory(

View File

@ -3,8 +3,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Server.Kestrel.Networking
{
@ -13,7 +14,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
/// </summary>
public class UvWriteReq : UvRequest
{
private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb;
private readonly Libuv.uv_write_cb _uv_write_cb;
private IntPtr _bufs;
@ -23,6 +24,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
private List<GCHandle> _pins = new List<GCHandle>();
public UvWriteReq(IKestrelTrace logger) : base(logger)
{
_uv_write_cb = UvWriteCb;
}
public void Init(UvLoopHandle loop)
{
var requestSize = loop.Libuv.req_size(Libuv.RequestType.WRITE);
@ -138,7 +144,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
req._pins.Clear();
}
private static void UvWriteCb(IntPtr ptr, int status)
private void UvWriteCb(IntPtr ptr, int status)
{
var req = FromIntPtr<UvWriteReq>(ptr);
Unpin(req);
@ -161,7 +167,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
}
catch (Exception ex)
{
Trace.WriteLine("UvWriteCb " + ex.ToString());
_log.LogError("UvWriteCb", ex);
}
}
}

View File

@ -8,11 +8,11 @@
"dependencies": {
"Microsoft.AspNet.Hosting": "1.0.0-*",
"Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*",
"Microsoft.Framework.Logging.Abstractions": "1.0.0-*",
"Microsoft.StandardsPolice": {
"version": "1.0.0-*",
"type": "build"
},
"Microsoft.Framework.Logging.Abstractions": "1.0.0-*"
}
},
"frameworks": {
"dnx451": { },

View File

@ -4,6 +4,7 @@ using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.AspNet.Server.Kestrel;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Server.Kestrel.Networking;
using Microsoft.Dnx.Runtime;
using Microsoft.Dnx.Runtime.Infrastructure;
@ -13,7 +14,8 @@ namespace Microsoft.AspNet.Server.KestrelTests
{
public class MultipleLoopTests
{
Libuv _uv;
private readonly Libuv _uv;
private readonly IKestrelTrace _logger = new KestrelTrace(new TestLogger());
public MultipleLoopTests()
{
var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger());
@ -41,8 +43,8 @@ namespace Microsoft.AspNet.Server.KestrelTests
[Fact]
public void InitAndCloseServerPipe()
{
var loop = new UvLoopHandle();
var pipe = new UvPipeHandle();
var loop = new UvLoopHandle(_logger);
var pipe = new UvPipeHandle(_logger);
loop.Init(_uv);
pipe.Init(loop, true);
@ -59,15 +61,15 @@ namespace Microsoft.AspNet.Server.KestrelTests
[Fact]
public void ServerPipeListenForConnections()
{
var loop = new UvLoopHandle();
var serverListenPipe = new UvPipeHandle();
var loop = new UvLoopHandle(_logger);
var serverListenPipe = new UvPipeHandle(_logger);
loop.Init(_uv);
serverListenPipe.Init(loop, false);
serverListenPipe.Bind(@"\\.\pipe\ServerPipeListenForConnections");
serverListenPipe.Listen(128, (_1, status, error, _2) =>
{
var serverConnectionPipe = new UvPipeHandle();
var serverConnectionPipe = new UvPipeHandle(_logger);
serverConnectionPipe.Init(loop, true);
try
{
@ -79,7 +81,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
return;
}
var writeRequest = new UvWriteReq();
var writeRequest = new UvWriteReq(new KestrelTrace(new TestLogger()));
writeRequest.Init(loop);
writeRequest.Write(
serverConnectionPipe,
@ -96,9 +98,9 @@ namespace Microsoft.AspNet.Server.KestrelTests
var worker = new Thread(() =>
{
var loop2 = new UvLoopHandle();
var clientConnectionPipe = new UvPipeHandle();
var connect = new UvConnectRequest();
var loop2 = new UvLoopHandle(_logger);
var clientConnectionPipe = new UvPipeHandle(_logger);
var connect = new UvConnectRequest(new KestrelTrace(new TestLogger()));
loop2.Init(_uv);
clientConnectionPipe.Init(loop2, true);
@ -134,19 +136,19 @@ namespace Microsoft.AspNet.Server.KestrelTests
{
var pipeName = @"\\.\pipe\ServerPipeDispatchConnections" + Guid.NewGuid().ToString("n");
var loop = new UvLoopHandle();
var loop = new UvLoopHandle(_logger);
loop.Init(_uv);
var serverConnectionPipe = default(UvPipeHandle);
var serverConnectionPipeAcceptedEvent = new ManualResetEvent(false);
var serverConnectionTcpDisposedEvent = new ManualResetEvent(false);
var serverListenPipe = new UvPipeHandle();
var serverListenPipe = new UvPipeHandle(_logger);
serverListenPipe.Init(loop, false);
serverListenPipe.Bind(pipeName);
serverListenPipe.Listen(128, (_1, status, error, _2) =>
{
serverConnectionPipe = new UvPipeHandle();
serverConnectionPipe = new UvPipeHandle(_logger);
serverConnectionPipe.Init(loop, true);
try
{
@ -161,18 +163,18 @@ namespace Microsoft.AspNet.Server.KestrelTests
}
}, null);
var serverListenTcp = new UvTcpHandle();
var serverListenTcp = new UvTcpHandle(_logger);
serverListenTcp.Init(loop);
serverListenTcp.Bind(new IPEndPoint(0, 54321));
serverListenTcp.Listen(128, (_1, status, error, _2) =>
{
var serverConnectionTcp = new UvTcpHandle();
var serverConnectionTcp = new UvTcpHandle(_logger);
serverConnectionTcp.Init(loop);
serverListenTcp.Accept(serverConnectionTcp);
serverConnectionPipeAcceptedEvent.WaitOne();
var writeRequest = new UvWriteReq();
var writeRequest = new UvWriteReq(new KestrelTrace(new TestLogger()));
writeRequest.Init(loop);
writeRequest.Write2(
serverConnectionPipe,
@ -192,9 +194,9 @@ namespace Microsoft.AspNet.Server.KestrelTests
var worker = new Thread(() =>
{
var loop2 = new UvLoopHandle();
var clientConnectionPipe = new UvPipeHandle();
var connect = new UvConnectRequest();
var loop2 = new UvLoopHandle(_logger);
var clientConnectionPipe = new UvPipeHandle(_logger);
var connect = new UvConnectRequest(new KestrelTrace(new TestLogger()));
loop2.Init(_uv);
clientConnectionPipe.Init(loop2, true);
@ -216,7 +218,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
clientConnectionPipe.Dispose();
return;
}
var clientConnectionTcp = new UvTcpHandle();
var clientConnectionTcp = new UvTcpHandle(_logger);
clientConnectionTcp.Init(loop2);
clientConnectionPipe.Accept(clientConnectionTcp);
var buf2 = loop2.Libuv.buf_init(Marshal.AllocHGlobal(64), 64);

View File

@ -7,6 +7,7 @@ using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Server.Kestrel.Networking;
using Microsoft.Dnx.Runtime;
using Microsoft.Dnx.Runtime.Infrastructure;
@ -19,7 +20,8 @@ namespace Microsoft.AspNet.Server.KestrelTests
/// </summary>
public class NetworkingTests
{
Libuv _uv;
private readonly Libuv _uv;
private readonly IKestrelTrace _logger = new KestrelTrace(new TestLogger());
public NetworkingTests()
{
var engine = new KestrelEngine(LibraryManager, new ShutdownNotImplemented(), new TestLogger());
@ -47,7 +49,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
[Fact]
public void LoopCanBeInitAndClose()
{
var loop = new UvLoopHandle();
var loop = new UvLoopHandle(_logger);
loop.Init(_uv);
loop.Run();
loop.Dispose();
@ -56,9 +58,9 @@ namespace Microsoft.AspNet.Server.KestrelTests
[Fact]
public void AsyncCanBeSent()
{
var loop = new UvLoopHandle();
var loop = new UvLoopHandle(_logger);
loop.Init(_uv);
var trigger = new UvAsyncHandle();
var trigger = new UvAsyncHandle(_logger);
var called = false;
trigger.Init(loop, () =>
{
@ -74,9 +76,9 @@ namespace Microsoft.AspNet.Server.KestrelTests
[Fact]
public void SocketCanBeInitAndClose()
{
var loop = new UvLoopHandle();
var loop = new UvLoopHandle(_logger);
loop.Init(_uv);
var tcp = new UvTcpHandle();
var tcp = new UvTcpHandle(_logger);
tcp.Init(loop);
tcp.Bind(new IPEndPoint(IPAddress.Loopback, 0));
tcp.Dispose();
@ -88,14 +90,14 @@ namespace Microsoft.AspNet.Server.KestrelTests
[Fact]
public async Task SocketCanListenAndAccept()
{
var loop = new UvLoopHandle();
var loop = new UvLoopHandle(_logger);
loop.Init(_uv);
var tcp = new UvTcpHandle();
var tcp = new UvTcpHandle(_logger);
tcp.Init(loop);
tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321));
tcp.Listen(10, (stream, status, error, state) =>
{
var tcp2 = new UvTcpHandle();
var tcp2 = new UvTcpHandle(_logger);
tcp2.Init(loop);
stream.Accept(tcp2);
tcp2.Dispose();
@ -125,15 +127,15 @@ namespace Microsoft.AspNet.Server.KestrelTests
public async Task SocketCanRead()
{
int bytesRead = 0;
var loop = new UvLoopHandle();
var loop = new UvLoopHandle(_logger);
loop.Init(_uv);
var tcp = new UvTcpHandle();
var tcp = new UvTcpHandle(_logger);
tcp.Init(loop);
tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321));
tcp.Listen(10, (_, status, error, state) =>
{
Console.WriteLine("Connected");
var tcp2 = new UvTcpHandle();
var tcp2 = new UvTcpHandle(_logger);
tcp2.Init(loop);
tcp.Accept(tcp2);
var data = Marshal.AllocCoTaskMem(500);
@ -181,15 +183,15 @@ namespace Microsoft.AspNet.Server.KestrelTests
public async Task SocketCanReadAndWrite()
{
int bytesRead = 0;
var loop = new UvLoopHandle();
var loop = new UvLoopHandle(_logger);
loop.Init(_uv);
var tcp = new UvTcpHandle();
var tcp = new UvTcpHandle(_logger);
tcp.Init(loop);
tcp.Bind(new IPEndPoint(IPAddress.Loopback, 54321));
tcp.Listen(10, (_, status, error, state) =>
{
Console.WriteLine("Connected");
var tcp2 = new UvTcpHandle();
var tcp2 = new UvTcpHandle(_logger);
tcp2.Init(loop);
tcp.Accept(tcp2);
var data = Marshal.AllocCoTaskMem(500);
@ -206,7 +208,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
{
for (var x = 0; x != 2; ++x)
{
var req = new UvWriteReq();
var req = new UvWriteReq(new KestrelTrace(new TestLogger()));
req.Init(loop);
req.Write(
tcp2,

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Threading;
using Microsoft.AspNet.Server.Kestrel;
using Microsoft.AspNet.Server.Kestrel.Http;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Server.Kestrel.Networking;
using Microsoft.AspNet.Server.KestrelTests.TestHelpers;
using Xunit;
@ -36,7 +37,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
kestrelEngine.Start(count: 1);
var kestrelThread = kestrelEngine.Threads[0];
var socket = new MockSocket(kestrelThread.Loop.ThreadId);
var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger()));
var trace = new KestrelTrace(new TestLogger());
var socketOutput = new SocketOutput(kestrelThread, socket, trace);
@ -81,7 +82,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
kestrelEngine.Start(count: 1);
var kestrelThread = kestrelEngine.Threads[0];
var socket = new MockSocket(kestrelThread.Loop.ThreadId);
var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger()));
var trace = new KestrelTrace(new TestLogger());
var socketOutput = new SocketOutput(kestrelThread, socket, trace);
@ -117,7 +118,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
private class MockSocket : UvStreamHandle
{
public MockSocket(int threadId)
public MockSocket(int threadId, IKestrelTrace logger) : base(logger)
{
// Set the handle to something other than IntPtr.Zero
// so handle.Validate doesn't fail in Libuv.write