Remove Kestrel.Core dependency from Transport.Libuv (#1584).

This commit is contained in:
Cesar Blum Silveira 2017-04-03 20:54:01 -07:00 committed by GitHub
parent fd5f3a771c
commit 6a66323a99
38 changed files with 240 additions and 208 deletions

View File

@ -1,3 +1,6 @@
// 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;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -9,30 +12,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
void ConnectionStop(string connectionId); void ConnectionStop(string connectionId);
void ConnectionRead(string connectionId, int count);
void ConnectionPause(string connectionId); void ConnectionPause(string connectionId);
void ConnectionResume(string connectionId); void ConnectionResume(string connectionId);
void ConnectionReadFin(string connectionId);
void ConnectionWriteFin(string connectionId);
void ConnectionWroteFin(string connectionId, int status);
void ConnectionKeepAlive(string connectionId); void ConnectionKeepAlive(string connectionId);
void ConnectionDisconnect(string connectionId); void ConnectionDisconnect(string connectionId);
void ConnectionWrite(string connectionId, int count);
void ConnectionWriteCallback(string connectionId, int status);
void ConnectionError(string connectionId, Exception ex);
void ConnectionReset(string connectionId);
void RequestProcessingError(string connectionId, Exception ex); void RequestProcessingError(string connectionId, Exception ex);
void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex);
@ -41,10 +28,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
void ConnectionBadRequest(string connectionId, BadHttpRequestException ex); void ConnectionBadRequest(string connectionId, BadHttpRequestException ex);
void NotAllConnectionsClosedGracefully();
void NotAllConnectionsAborted();
void ApplicationError(string connectionId, string traceIdentifier, Exception ex); void ApplicationError(string connectionId, string traceIdentifier, Exception ex);
} }
} }

View File

@ -18,60 +18,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
private static readonly Action<ILogger, string, Exception> _connectionStop = private static readonly Action<ILogger, string, Exception> _connectionStop =
LoggerMessage.Define<string>(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); LoggerMessage.Define<string>(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped.");
// ConnectionRead: Reserved: 3
private static readonly Action<ILogger, string, Exception> _connectionPause = private static readonly Action<ILogger, string, Exception> _connectionPause =
LoggerMessage.Define<string>(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); LoggerMessage.Define<string>(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused.");
private static readonly Action<ILogger, string, Exception> _connectionResume = private static readonly Action<ILogger, string, Exception> _connectionResume =
LoggerMessage.Define<string>(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); LoggerMessage.Define<string>(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed.");
private static readonly Action<ILogger, string, Exception> _connectionReadFin =
LoggerMessage.Define<string>(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN.");
private static readonly Action<ILogger, string, Exception> _connectionWriteFin =
LoggerMessage.Define<string>(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN.");
private static readonly Action<ILogger, string, int, Exception> _connectionWroteFin =
LoggerMessage.Define<string, int>(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".");
private static readonly Action<ILogger, string, Exception> _connectionKeepAlive = private static readonly Action<ILogger, string, Exception> _connectionKeepAlive =
LoggerMessage.Define<string>(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); LoggerMessage.Define<string>(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response.");
private static readonly Action<ILogger, string, Exception> _connectionDisconnect = private static readonly Action<ILogger, string, Exception> _connectionDisconnect =
LoggerMessage.Define<string>(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); LoggerMessage.Define<string>(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting.");
// ConnectionWrite: Reserved: 11
// ConnectionWriteCallback: Reserved: 12
private static readonly Action<ILogger, string, string, Exception> _applicationError = private static readonly Action<ILogger, string, string, Exception> _applicationError =
LoggerMessage.Define<string, string>(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": An unhandled exception was thrown by the application."); LoggerMessage.Define<string, string>(LogLevel.Error, 13, @"Connection id ""{ConnectionId}"", Request id ""{TraceIdentifier}"": An unhandled exception was thrown by the application.");
private static readonly Action<ILogger, string, Exception> _connectionError =
LoggerMessage.Define<string>(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error.");
private static readonly Action<ILogger, string, int, Exception> _connectionDisconnectedWrite = private static readonly Action<ILogger, string, int, Exception> _connectionDisconnectedWrite =
LoggerMessage.Define<string, int>(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); LoggerMessage.Define<string, int>(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client.");
private static readonly Action<ILogger, Exception> _notAllConnectionsClosedGracefully =
LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown.");
private static readonly Action<ILogger, string, string, Exception> _connectionBadRequest = private static readonly Action<ILogger, string, string, Exception> _connectionBadRequest =
LoggerMessage.Define<string, string>(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}"""); LoggerMessage.Define<string, string>(LogLevel.Information, 17, @"Connection id ""{ConnectionId}"" bad request data: ""{message}""");
private static readonly Action<ILogger, string, long, Exception> _connectionHeadResponseBodyWrite = private static readonly Action<ILogger, string, long, Exception> _connectionHeadResponseBodyWrite =
LoggerMessage.Define<string, long>(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response."); LoggerMessage.Define<string, long>(LogLevel.Debug, 18, @"Connection id ""{ConnectionId}"" write of ""{count}"" body bytes to non-body HEAD response.");
private static readonly Action<ILogger, string, Exception> _connectionReset =
LoggerMessage.Define<string>(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset.");
private static readonly Action<ILogger, string, Exception> _requestProcessingError = private static readonly Action<ILogger, string, Exception> _requestProcessingError =
LoggerMessage.Define<string>(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally."); LoggerMessage.Define<string>(LogLevel.Information, 20, @"Connection id ""{ConnectionId}"" request processing ended abnormally.");
private static readonly Action<ILogger, Exception> _notAllConnectionsAborted =
LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown.");
protected readonly ILogger _logger; protected readonly ILogger _logger;
public KestrelTrace(ILogger logger) public KestrelTrace(ILogger logger)
@ -89,12 +62,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
_connectionStop(_logger, connectionId, null); _connectionStop(_logger, connectionId, null);
} }
public virtual void ConnectionRead(string connectionId, int count)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 3
}
public virtual void ConnectionPause(string connectionId) public virtual void ConnectionPause(string connectionId)
{ {
_connectionPause(_logger, connectionId, null); _connectionPause(_logger, connectionId, null);
@ -105,21 +72,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
_connectionResume(_logger, connectionId, null); _connectionResume(_logger, connectionId, null);
} }
public virtual void ConnectionReadFin(string connectionId)
{
_connectionReadFin(_logger, connectionId, null);
}
public virtual void ConnectionWriteFin(string connectionId)
{
_connectionWriteFin(_logger, connectionId, null);
}
public virtual void ConnectionWroteFin(string connectionId, int status)
{
_connectionWroteFin(_logger, connectionId, status, null);
}
public virtual void ConnectionKeepAlive(string connectionId) public virtual void ConnectionKeepAlive(string connectionId)
{ {
_connectionKeepAlive(_logger, connectionId, null); _connectionKeepAlive(_logger, connectionId, null);
@ -130,28 +82,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
_connectionDisconnect(_logger, connectionId, null); _connectionDisconnect(_logger, connectionId, null);
} }
public virtual void ConnectionWrite(string connectionId, int count)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 11
}
public virtual void ConnectionWriteCallback(string connectionId, int status)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 12
}
public virtual void ApplicationError(string connectionId, string traceIdentifier, Exception ex) public virtual void ApplicationError(string connectionId, string traceIdentifier, Exception ex)
{ {
_applicationError(_logger, connectionId, traceIdentifier, ex); _applicationError(_logger, connectionId, traceIdentifier, ex);
} }
public virtual void ConnectionError(string connectionId, Exception ex)
{
_connectionError(_logger, connectionId, ex);
}
public virtual void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) public virtual void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex)
{ {
_connectionDisconnectedWrite(_logger, connectionId, count, ex); _connectionDisconnectedWrite(_logger, connectionId, count, ex);
@ -162,44 +97,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
_connectionHeadResponseBodyWrite(_logger, connectionId, count, null); _connectionHeadResponseBodyWrite(_logger, connectionId, count, null);
} }
public virtual void NotAllConnectionsClosedGracefully()
{
_notAllConnectionsClosedGracefully(_logger, null);
}
public virtual void NotAllConnectionsAborted()
{
_notAllConnectionsAborted(_logger, null);
}
public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex)
{ {
_connectionBadRequest(_logger, connectionId, ex.Message, ex); _connectionBadRequest(_logger, connectionId, ex.Message, ex);
} }
public virtual void ConnectionReset(string connectionId)
{
_connectionReset(_logger, connectionId, null);
}
public virtual void RequestProcessingError(string connectionId, Exception ex) public virtual void RequestProcessingError(string connectionId, Exception ex)
{ {
_requestProcessingError(_logger, connectionId, ex); _requestProcessingError(_logger, connectionId, ex);
} }
public virtual void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) public virtual void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{ => _logger.Log(logLevel, eventId, state, exception, formatter);
_logger.Log(logLevel, eventId, state, exception, formatter);
}
public virtual bool IsEnabled(LogLevel logLevel) public virtual bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);
{
return _logger.IsEnabled(logLevel);
}
public virtual IDisposable BeginScope<TState>(TState state) public virtual IDisposable BeginScope<TState>(TState state) => _logger.BeginScope(state);
{
return _logger.BeginScope(state);
}
} }
} }

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
@ -56,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel
Options = options.Value ?? new KestrelServerOptions(); Options = options.Value ?? new KestrelServerOptions();
InternalOptions = new InternalKestrelServerOptions(); InternalOptions = new InternalKestrelServerOptions();
_transportFactory = transportFactory; _transportFactory = transportFactory;
_logger = loggerFactory.CreateLogger(typeof(KestrelServer).GetTypeInfo().Namespace); _logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel");
Features = new FeatureCollection(); Features = new FeatureCollection();
_serverAddresses = new ServerAddressesFeature(); _serverAddresses = new ServerAddressesFeature();
Features.Set(_serverAddresses); Features.Set(_serverAddresses);

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
@ -59,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
public IPipeWriter Input { get; set; } public IPipeWriter Input { get; set; }
public SocketOutputConsumer Output { get; set; } public SocketOutputConsumer Output { get; set; }
private IKestrelTrace Log => ListenerContext.TransportContext.Log; private ILibuvTrace Log => ListenerContext.TransportContext.Log;
private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler; private IConnectionHandler ConnectionHandler => ListenerContext.TransportContext.ConnectionHandler;
private KestrelThread Thread => ListenerContext.Thread; private KestrelThread Thread => ListenerContext.Thread;

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
@ -24,7 +25,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
protected UvStreamHandle ListenSocket { get; private set; } protected UvStreamHandle ListenSocket { get; private set; }
public IKestrelTrace Log => TransportContext.Log; public ILibuvTrace Log => TransportContext.Log;
public Task StartAsync( public Task StartAsync(
IEndPointInformation endPointInformation, IEndPointInformation endPointInformation,

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
@ -32,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
UvPipeHandle DispatchPipe { get; set; } UvPipeHandle DispatchPipe { get; set; }
public IKestrelTrace Log => TransportContext.Log; public ILibuvTrace Log => TransportContext.Log;
public Task StartAsync( public Task StartAsync(
string pipeName, string pipeName,

View File

@ -6,6 +6,7 @@ using System.IO.Pipelines;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
private readonly UvStreamHandle _socket; private readonly UvStreamHandle _socket;
private readonly Connection _connection; private readonly Connection _connection;
private readonly string _connectionId; private readonly string _connectionId;
private readonly IKestrelTrace _log; private readonly ILibuvTrace _log;
private readonly WriteReqPool _writeReqPool; private readonly WriteReqPool _writeReqPool;
private readonly IPipeReader _pipe; private readonly IPipeReader _pipe;
@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
UvStreamHandle socket, UvStreamHandle socket,
Connection connection, Connection connection,
string connectionId, string connectionId,
IKestrelTrace log) ILibuvTrace log)
{ {
_pipe = pipe; _pipe = pipe;
// We need to have empty pipe at this moment so callback // We need to have empty pipe at this moment so callback

View File

@ -0,0 +1,31 @@
// 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.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure
{
public interface ILibuvTrace : ILogger
{
void ConnectionRead(string connectionId, int count);
void ConnectionReadFin(string connectionId);
void ConnectionWriteFin(string connectionId);
void ConnectionWroteFin(string connectionId, int status);
void ConnectionWrite(string connectionId, int count);
void ConnectionWriteCallback(string connectionId, int status);
void ConnectionError(string connectionId, Exception ex);
void ConnectionReset(string connectionId);
void NotAllConnectionsClosedGracefully();
void NotAllConnectionsAborted();
}
}

View File

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Internal
@ -52,7 +53,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
private bool _stopImmediate = false; private bool _stopImmediate = false;
private bool _initCompleted = false; private bool _initCompleted = false;
private ExceptionDispatchInfo _closeError; private ExceptionDispatchInfo _closeError;
private readonly IKestrelTrace _log; private readonly ILibuvTrace _log;
private readonly TimeSpan _shutdownTimeout; private readonly TimeSpan _shutdownTimeout;
private IntPtr _thisPtr; private IntPtr _thisPtr;

View File

@ -0,0 +1,105 @@
// 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.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure
{
public class LibuvTrace : ILibuvTrace
{
// ConnectionRead: Reserved: 3
private static readonly Action<ILogger, string, Exception> _connectionReadFin =
LoggerMessage.Define<string>(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN.");
private static readonly Action<ILogger, string, Exception> _connectionWriteFin =
LoggerMessage.Define<string>(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN.");
private static readonly Action<ILogger, string, int, Exception> _connectionWroteFin =
LoggerMessage.Define<string, int>(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}"".");
// ConnectionWrite: Reserved: 11
// ConnectionWriteCallback: Reserved: 12
private static readonly Action<ILogger, string, Exception> _connectionError =
LoggerMessage.Define<string>(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error.");
private static readonly Action<ILogger, Exception> _notAllConnectionsClosedGracefully =
LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown.");
private static readonly Action<ILogger, string, Exception> _connectionReset =
LoggerMessage.Define<string>(LogLevel.Debug, 19, @"Connection id ""{ConnectionId}"" reset.");
private static readonly Action<ILogger, Exception> _notAllConnectionsAborted =
LoggerMessage.Define(LogLevel.Debug, 21, "Some connections failed to abort during server shutdown.");
private readonly ILogger _logger;
public LibuvTrace(ILogger logger)
{
_logger = logger;
}
public void ConnectionRead(string connectionId, int count)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 3
}
public void ConnectionReadFin(string connectionId)
{
_connectionReadFin(_logger, connectionId, null);
}
public void ConnectionWriteFin(string connectionId)
{
_connectionWriteFin(_logger, connectionId, null);
}
public void ConnectionWroteFin(string connectionId, int status)
{
_connectionWroteFin(_logger, connectionId, status, null);
}
public void ConnectionWrite(string connectionId, int count)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 11
}
public void ConnectionWriteCallback(string connectionId, int status)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 12
}
public void ConnectionError(string connectionId, Exception ex)
{
_connectionError(_logger, connectionId, ex);
}
public void ConnectionReset(string connectionId)
{
_connectionReset(_logger, connectionId, null);
}
public void NotAllConnectionsClosedGracefully()
{
_notAllConnectionsClosedGracefully(_logger, null);
}
public void NotAllConnectionsAborted()
{
_notAllConnectionsAborted(_logger, null);
}
public IDisposable BeginScope<TState>(TState state) => _logger.BeginScope(state);
public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
=> _logger.Log(logLevel, eventId, state, exception, formatter);
}
}

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
{ {
@ -10,10 +11,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
private readonly KestrelThread _thread; private readonly KestrelThread _thread;
private readonly Queue<UvWriteReq> _pool = new Queue<UvWriteReq>(_maxPooledWriteReqs); private readonly Queue<UvWriteReq> _pool = new Queue<UvWriteReq>(_maxPooledWriteReqs);
private readonly IKestrelTrace _log; private readonly ILibuvTrace _log;
private bool _disposed; private bool _disposed;
public WriteReqPool(KestrelThread thread, IKestrelTrace log) public WriteReqPool(KestrelThread thread, ILibuvTrace log)
{ {
_thread = thread; _thread = thread;
_log = log; _log = log;

View File

@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{ {
@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
public IApplicationLifetime AppLifetime { get; set; } public IApplicationLifetime AppLifetime { get; set; }
public IKestrelTrace Log { get; set; } public ILibuvTrace Log { get; set; }
public IConnectionHandler ConnectionHandler { get; set; } public IConnectionHandler ConnectionHandler { get; set; }
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
private Action _callback; private Action _callback;
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle; private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;
public UvAsyncHandle(IKestrelTrace logger) : base(logger) public UvAsyncHandle(ILibuvTrace logger) : base(logger)
{ {
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
private Action<UvConnectRequest, int, Exception, object> _callback; private Action<UvConnectRequest, int, Exception, object> _callback;
private object _state; private object _state;
public UvConnectRequest(IKestrelTrace logger) : base (logger) public UvConnectRequest(ILibuvTrace logger) : base (logger)
{ {
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
private static readonly LibuvFunctions.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); private static readonly LibuvFunctions.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle);
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle; private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;
protected UvHandle(IKestrelTrace logger) : base (logger) protected UvHandle(ILibuvTrace logger) : base (logger)
{ {
} }

View File

@ -4,12 +4,13 @@
using System; using System;
using System.Threading; using System.Threading;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
public class UvLoopHandle : UvMemory public class UvLoopHandle : UvMemory
{ {
public UvLoopHandle(IKestrelTrace logger) : base(logger) public UvLoopHandle(ILibuvTrace logger) : base(logger)
{ {
} }

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
@ -16,9 +17,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
protected LibuvFunctions _uv; protected LibuvFunctions _uv;
protected int _threadId; protected int _threadId;
protected readonly IKestrelTrace _log; protected readonly ILibuvTrace _log;
protected UvMemory(IKestrelTrace logger) : base(IntPtr.Zero, true) protected UvMemory(ILibuvTrace logger) : base(IntPtr.Zero, true)
{ {
_log = logger; _log = logger;
} }

View File

@ -3,12 +3,13 @@
using System; using System;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
public class UvPipeHandle : UvStreamHandle public class UvPipeHandle : UvStreamHandle
{ {
public UvPipeHandle(IKestrelTrace logger) : base(logger) public UvPipeHandle(ILibuvTrace logger) : base(logger)
{ {
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
@ -8,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
private GCHandle _pin; private GCHandle _pin;
protected UvRequest(IKestrelTrace logger) : base (logger) protected UvRequest(ILibuvTrace logger) : base (logger)
{ {
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
private Action<UvShutdownReq, int, object> _callback; private Action<UvShutdownReq, int, object> _callback;
private object _state; private object _state;
public UvShutdownReq(IKestrelTrace logger) : base (logger) public UvShutdownReq(ILibuvTrace logger) : base (logger)
{ {
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
private object _readState; private object _readState;
private GCHandle _readVitality; private GCHandle _readVitality;
protected UvStreamHandle(IKestrelTrace logger) : base(logger) protected UvStreamHandle(ILibuvTrace logger) : base(logger)
{ {
} }

View File

@ -5,12 +5,13 @@ using System;
using System.Net; using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
{ {
public class UvTcpHandle : UvStreamHandle public class UvTcpHandle : UvStreamHandle
{ {
public UvTcpHandle(IKestrelTrace logger) : base(logger) public UvTcpHandle(ILibuvTrace logger) : base(logger)
{ {
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
private Action<UvTimerHandle> _callback; private Action<UvTimerHandle> _callback;
public UvTimerHandle(IKestrelTrace logger) : base(logger) public UvTimerHandle(ILibuvTrace logger) : base(logger)
{ {
} }

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
private List<GCHandle> _pins = new List<GCHandle>(BUFFER_COUNT + 1); private List<GCHandle> _pins = new List<GCHandle>(BUFFER_COUNT + 1);
private List<BufferHandle> _handles = new List<BufferHandle>(BUFFER_COUNT + 1); private List<BufferHandle> _handles = new List<BufferHandle>(BUFFER_COUNT + 1);
public UvWriteReq(IKestrelTrace logger) : base(logger) public UvWriteReq(ILibuvTrace logger) : base(logger)
{ {
} }

View File

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Internal
@ -40,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
public List<KestrelThread> Threads { get; } = new List<KestrelThread>(); public List<KestrelThread> Threads { get; } = new List<KestrelThread>();
public IApplicationLifetime AppLifetime => TransportContext.AppLifetime; public IApplicationLifetime AppLifetime => TransportContext.AppLifetime;
public IKestrelTrace Log => TransportContext.Log; public ILibuvTrace Log => TransportContext.Log;
public LibuvTransportOptions TransportOptions => TransportContext.Options; public LibuvTransportOptions TransportOptions => TransportContext.Options;
public async Task StopAsync() public async Task StopAsync()

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -34,10 +35,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
throw new ArgumentNullException(nameof(loggerFactory)); throw new ArgumentNullException(nameof(loggerFactory));
} }
// REVIEW: Should we change the logger namespace for transport logs? var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv");
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"); var trace = new LibuvTrace(logger);
// TODO: Add LibuvTrace
var trace = new KestrelTrace(logger);
var threadCount = options.Value.ThreadCount; var threadCount = options.Value.ThreadCount;

View File

@ -4,7 +4,7 @@
<PropertyGroup> <PropertyGroup>
<Description>Libuv transport for the ASP.NET Core Kestrel cross-platform web server.</Description> <Description>Libuv transport for the ASP.NET Core Kestrel cross-platform web server.</Description>
<TargetFrameworks>netstandard1.3;net46</TargetFrameworks> <TargetFramework>netstandard1.3</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;kestrel</PackageTags> <PackageTags>aspnetcore;kestrel</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -13,12 +13,17 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Threading.Thread" Version="$(CoreFxVersion)" />
<PackageReference Include="System.Threading.ThreadPool" Version="$(CoreFxVersion)" />
<PackageReference Include="Libuv" Version="$(LibUvVersion)" /> <PackageReference Include="Libuv" Version="$(LibUvVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" /> <PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Server.Kestrel.Core\Microsoft.AspNetCore.Server.Kestrel.Core.csproj" /> <ProjectReference Include="..\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
Thread = thread Thread = thread
}; };
var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.Log); var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, serviceContext.TransportContext.Log);
var connection = new Connection(listenerContext, socket); var connection = new Connection(listenerContext, socket);
connection.Start(); connection.Start();

View File

@ -27,11 +27,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
} }
[Fact] [Fact]
public void LoggerCategoryNameIsKestrelServerNamespace() public void LoggerCategoryNameIsLibuvTransportNamespace()
{ {
var mockLoggerFactory = new Mock<ILoggerFactory>(); var mockLoggerFactory = new Mock<ILoggerFactory>();
new LibuvTransportFactory(Options.Create<LibuvTransportOptions>(new LibuvTransportOptions()), new LifetimeNotImplemented(), mockLoggerFactory.Object); new LibuvTransportFactory(Options.Create<LibuvTransportOptions>(new LibuvTransportOptions()), new LifetimeNotImplemented(), mockLoggerFactory.Object);
mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")); mockLoggerFactory.Verify(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv"));
} }
} }
} }

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -116,7 +117,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
// Create a pipe connection and keep it open without sending any data // Create a pipe connection and keep it open without sending any data
var connectTcs = new TaskCompletionSource<object>(); var connectTcs = new TaskCompletionSource<object>();
var connectionTrace = new TestKestrelTrace(); var connectionTrace = new LibuvTrace(new TestApplicationErrorLogger());
var pipe = new UvPipeHandle(connectionTrace); var pipe = new UvPipeHandle(connectionTrace);
kestrelThreadPrimary.Post(_ => kestrelThreadPrimary.Post(_ =>

View File

@ -7,9 +7,8 @@ using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Xunit; using Xunit;
@ -18,13 +17,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
public class MultipleLoopTests public class MultipleLoopTests
{ {
private readonly LibuvFunctions _uv; private readonly LibuvFunctions _uv = new LibuvFunctions();
private readonly IKestrelTrace _logger; private readonly ILibuvTrace _logger = new LibuvTrace(new TestApplicationErrorLogger());
public MultipleLoopTests()
{
_uv = new LibuvFunctions();
_logger = new TestKestrelTrace();
}
[Fact] [Fact]
public void InitAndCloseServerPipe() public void InitAndCloseServerPipe()
@ -41,7 +35,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
pipe.Dispose(); pipe.Dispose();
loop.Dispose(); loop.Dispose();
} }
[Fact] [Fact]
@ -70,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
return; return;
} }
var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); var writeRequest = new UvWriteReq(_logger);
writeRequest.Init(loop); writeRequest.Init(loop);
await writeRequest.WriteAsync( await writeRequest.WriteAsync(
@ -87,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
var loop2 = new UvLoopHandle(_logger); var loop2 = new UvLoopHandle(_logger);
var clientConnectionPipe = new UvPipeHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger);
var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); var connect = new UvConnectRequest(_logger);
loop2.Init(_uv); loop2.Init(_uv);
clientConnectionPipe.Init(loop2, (a, b) => { }, true); clientConnectionPipe.Init(loop2, (a, b) => { }, true);
@ -163,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
serverConnectionPipeAcceptedEvent.WaitOne(); serverConnectionPipeAcceptedEvent.WaitOne();
var writeRequest = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); var writeRequest = new UvWriteReq(_logger);
writeRequest.Init(loop); writeRequest.Init(loop);
writeRequest.Write2( writeRequest.Write2(
serverConnectionPipe, serverConnectionPipe,
@ -185,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
var loop2 = new UvLoopHandle(_logger); var loop2 = new UvLoopHandle(_logger);
var clientConnectionPipe = new UvPipeHandle(_logger); var clientConnectionPipe = new UvPipeHandle(_logger);
var connect = new UvConnectRequest(new KestrelTrace(new TestKestrelTrace())); var connect = new UvConnectRequest(_logger);
loop2.Init(_uv); loop2.Init(_uv);
clientConnectionPipe.Init(loop2, (a, b) => { }, true); clientConnectionPipe.Init(loop2, (a, b) => { }, true);

View File

@ -7,10 +7,10 @@ using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Moq;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
@ -20,13 +20,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
/// </summary> /// </summary>
public class NetworkingTests public class NetworkingTests
{ {
private readonly LibuvFunctions _uv; private readonly LibuvFunctions _uv = new LibuvFunctions();
private readonly IKestrelTrace _logger; private readonly ILibuvTrace _logger = new LibuvTrace(new TestApplicationErrorLogger());
public NetworkingTests()
{
_uv = new LibuvFunctions();
_logger = new TestKestrelTrace();
}
[Fact] [Fact]
public void LoopCanBeInitAndClose() public void LoopCanBeInitAndClose()
@ -69,7 +64,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
loop.Dispose(); loop.Dispose();
} }
[Fact] [Fact]
public async Task SocketCanListenAndAccept() public async Task SocketCanListenAndAccept()
{ {
@ -98,7 +92,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
await t; await t;
} }
[Fact] [Fact]
public async Task SocketCanRead() public async Task SocketCanRead()
{ {
@ -167,7 +160,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
for (var x = 0; x < 2; x++) for (var x = 0; x < 2; x++)
{ {
var req = new UvWriteReq(new KestrelTrace(new TestKestrelTrace())); var req = new UvWriteReq(_logger);
req.Init(loop); req.Init(loop);
var block = ReadableBuffer.Create(new byte[] { 65, 66, 67, 68, 69 }); var block = ReadableBuffer.Create(new byte[] { 65, 66, 67, 68, 69 });

View File

@ -520,13 +520,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
var pipe = _pipeFactory.Create(pipeOptions); var pipe = _pipeFactory.Create(pipeOptions);
var serviceContext = new TestServiceContext(); var serviceContext = new TestServiceContext();
var trace = serviceContext.Log;
var frame = new Frame<object>(null, new FrameContext { ServiceContext = serviceContext }); var frame = new Frame<object>(null, new FrameContext { ServiceContext = serviceContext });
var socket = new MockSocket(_mockLibuv, _kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var socket = new MockSocket(_mockLibuv, _kestrelThread.Loop.ThreadId, serviceContext.TransportContext.Log);
var socketOutput = new SocketOutputProducer(pipe.Writer, frame, "0", trace); var socketOutput = new SocketOutputProducer(pipe.Writer, frame, "0", serviceContext.Log);
var consumer = new SocketOutputConsumer(pipe.Reader, _kestrelThread, socket, connection ?? new MockConnection(), "0", trace); var consumer = new SocketOutputConsumer(pipe.Reader, _kestrelThread, socket, connection ?? new MockConnection(), "0", serviceContext.TransportContext.Log);
var ignore = consumer.StartWrites(); var ignore = consumer.StartWrites();
return socketOutput; return socketOutput;

View File

@ -1,12 +1,15 @@
using System; // Copyright (c) .NET Foundation. All rights reserved.
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
{ {
class MockSocket : UvStreamHandle class MockSocket : UvStreamHandle
{ {
public MockSocket(LibuvFunctions uv, int threadId, IKestrelTrace logger) : base(logger) public MockSocket(LibuvFunctions uv, int threadId, ILibuvTrace logger) : base(logger)
{ {
CreateMemory(uv, threadId, IntPtr.Size); CreateMemory(uv, threadId, IntPtr.Size);
} }

View File

@ -1,9 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
using Microsoft.AspNetCore.Testing;
using Moq; using Moq;
using Xunit; using Xunit;
@ -14,12 +15,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
[Fact] [Fact]
public void ReadStopIsIdempotent() public void ReadStopIsIdempotent()
{ {
var mockKestrelTrace = Mock.Of<IKestrelTrace>(); var libuvTrace = new LibuvTrace(new TestApplicationErrorLogger());
var mockUvLoopHandle = new Mock<UvLoopHandle>(mockKestrelTrace).Object;
var mockUvLoopHandle = new Mock<UvLoopHandle>(libuvTrace).Object;
mockUvLoopHandle.Init(new MockLibuv()); mockUvLoopHandle.Init(new MockLibuv());
// Need to mock UvTcpHandle instead of UvStreamHandle, since the latter lacks an Init() method // Need to mock UvTcpHandle instead of UvStreamHandle, since the latter lacks an Init() method
var mockUvStreamHandle = new Mock<UvTcpHandle>(mockKestrelTrace).Object; var mockUvStreamHandle = new Mock<UvTcpHandle>(libuvTrace).Object;
mockUvStreamHandle.Init(mockUvLoopHandle, null); mockUvStreamHandle.Init(mockUvLoopHandle, null);
mockUvStreamHandle.ReadStop(); mockUvStreamHandle.ReadStop();

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Xunit; using Xunit;
@ -9,15 +10,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
public class UvTimerHandleTests public class UvTimerHandleTests
{ {
private readonly ILibuvTrace _trace = new LibuvTrace(new TestApplicationErrorLogger());
[Fact] [Fact]
public void TestTimeout() public void TestTimeout()
{ {
var trace = new TestKestrelTrace(); var loop = new UvLoopHandle(_trace);
var loop = new UvLoopHandle(trace);
loop.Init(new LibuvFunctions()); loop.Init(new LibuvFunctions());
var timer = new UvTimerHandle(trace); var timer = new UvTimerHandle(_trace);
timer.Init(loop, (a, b) => { }); timer.Init(loop, (a, b) => { });
var callbackInvoked = false; var callbackInvoked = false;
@ -38,12 +39,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
[Fact] [Fact]
public void TestRepeat() public void TestRepeat()
{ {
var trace = new TestKestrelTrace(); var loop = new UvLoopHandle(_trace);
var loop = new UvLoopHandle(trace);
loop.Init(new LibuvFunctions()); loop.Init(new LibuvFunctions());
var timer = new UvTimerHandle(trace); var timer = new UvTimerHandle(_trace);
timer.Init(loop, (callback, handle) => { }); timer.Init(loop, (callback, handle) => { });
var callbackCount = 0; var callbackCount = 0;

View File

@ -17,20 +17,5 @@ namespace Microsoft.AspNetCore.Testing
} }
public TestApplicationErrorLogger Logger { get; private set; } public TestApplicationErrorLogger Logger { get; private set; }
public override void ConnectionRead(string connectionId, int count)
{
//_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count);
}
public override void ConnectionWrite(string connectionId, int count)
{
//_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count);
}
public override void ConnectionWriteCallback(string connectionId, int status)
{
//_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status);
}
} }
} }

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Testing namespace Microsoft.AspNetCore.Testing
{ {
@ -16,7 +17,9 @@ namespace Microsoft.AspNetCore.Testing
{ {
public TestServiceContext() public TestServiceContext()
{ {
Log = new TestKestrelTrace(); var logger = new TestApplicationErrorLogger();
Log = new TestKestrelTrace(logger);
ThreadPool = new LoggingThreadPool(Log); ThreadPool = new LoggingThreadPool(Log);
DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock()); DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock());
DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String; DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String;
@ -29,7 +32,7 @@ namespace Microsoft.AspNetCore.Testing
TransportContext = new LibuvTransportContext TransportContext = new LibuvTransportContext
{ {
AppLifetime = new LifetimeNotImplemented(), AppLifetime = new LifetimeNotImplemented(),
Log = Log, Log = new LibuvTrace(logger),
Options = new LibuvTransportOptions Options = new LibuvTransportOptions
{ {
ThreadCount = 1, ThreadCount = 1,