From aef612bdac07d8cf53253b1e0c3bc364a934c199 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 18 Feb 2016 10:59:12 -0800 Subject: [PATCH] Add IHttpConnectionFeature.ConnectionId. --- .../Http/Connection.cs | 66 ++++++++++++----- .../Http/ConnectionContext.cs | 18 +++++ .../Http/Frame.FeatureCollection.cs | 2 + .../Http/Frame.cs | 27 ++----- .../Http/FrameOfT.cs | 11 +-- .../Http/SocketOutput.cs | 4 +- .../Infrastructure/IKestrelTrace.cs | 28 ++++---- .../Infrastructure/KestrelTrace.cs | 72 +++++++++---------- .../KestrelServer.cs | 4 +- .../ServiceContext.cs | 2 +- .../SocketOutputTests.cs | 14 ++-- .../TestLogger.cs | 6 +- .../TestServer.cs | 4 +- .../TestServiceContext.cs | 4 +- 14 files changed, 145 insertions(+), 117 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index d49738193e..3cc06e8521 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Filter; @@ -14,18 +13,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class Connection : ConnectionContext, IConnectionControl { + // Base32 encoding - in ascii sort order for easy text based sorting + private static readonly string _encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; + private static readonly Action _readCallback = (handle, status, state) => ReadCallback(handle, status, state); private static readonly Func _allocCallback = (handle, suggestedsize, state) => AllocCallback(handle, suggestedsize, state); - private static long _lastConnectionId; + // Seed the _lastConnectionId for this application instance with + // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 + // for a roughly increasing _requestId over restarts + private static long _lastConnectionId = DateTime.UtcNow.Ticks; private readonly UvStreamHandle _socket; private Frame _frame; private ConnectionFilterContext _filterContext; private LibuvStream _libuvStream; - private readonly long _connectionId; private readonly SocketInput _rawSocketInput; private readonly SocketOutput _rawSocketOutput; @@ -34,19 +38,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private ConnectionState _connectionState; private TaskCompletionSource _socketClosedTcs; - private IPEndPoint _remoteEndPoint; - private IPEndPoint _localEndPoint; - public Connection(ListenerContext context, UvStreamHandle socket) : base(context) { _socket = socket; socket.Connection = this; ConnectionControl = this; - _connectionId = Interlocked.Increment(ref _lastConnectionId); + ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId)); _rawSocketInput = new SocketInput(Memory2, ThreadPool); - _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool, WriteReqPool); + _rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, ConnectionId, Log, ThreadPool, WriteReqPool); } // Internal for testing @@ -56,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public void Start() { - Log.ConnectionStart(_connectionId); + Log.ConnectionStart(ConnectionId); // Start socket prior to applying the ConnectionFilter _socket.ReadStart(_allocCallback, _readCallback, this); @@ -64,8 +65,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var tcpHandle = _socket as UvTcpHandle; if (tcpHandle != null) { - _remoteEndPoint = tcpHandle.GetPeerIPEndPoint(); - _localEndPoint = tcpHandle.GetSockIPEndPoint(); + RemoteEndPoint = tcpHandle.GetPeerIPEndPoint(); + LocalEndPoint = tcpHandle.GetSockIPEndPoint(); } // Don't initialize _frame until SocketInput and SocketOutput are set to their final values. @@ -218,6 +219,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http SocketOutput = _rawSocketOutput; } + PrepareRequest = _filterContext.PrepareRequest; + _frame = CreateFrame(); _frame.Start(); } @@ -256,12 +259,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (normalRead) { - Log.ConnectionRead(_connectionId, readCount); + Log.ConnectionRead(ConnectionId, readCount); } else { _socket.ReadStop(); - Log.ConnectionReadFin(_connectionId); + Log.ConnectionReadFin(ConnectionId); } Exception error = null; @@ -280,18 +283,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private Frame CreateFrame() { - return FrameFactory(this, _remoteEndPoint, _localEndPoint, _filterContext?.PrepareRequest); + return FrameFactory(this); } void IConnectionControl.Pause() { - Log.ConnectionPause(_connectionId); + Log.ConnectionPause(ConnectionId); _socket.ReadStop(); } void IConnectionControl.Resume() { - Log.ConnectionResume(_connectionId); + Log.ConnectionResume(ConnectionId); _socket.ReadStart(_allocCallback, _readCallback, this); } @@ -307,7 +310,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http return; } - Log.ConnectionKeepAlive(_connectionId); + Log.ConnectionKeepAlive(ConnectionId); break; case ProduceEndType.SocketShutdown: case ProduceEndType.SocketDisconnect: @@ -318,13 +321,40 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } _connectionState = ConnectionState.Disconnecting; - Log.ConnectionDisconnect(_connectionId); + Log.ConnectionDisconnect(ConnectionId); _rawSocketOutput.End(endType); break; } } } + private static unsafe string GenerateConnectionId(long id) + { + // The following routine is ~310% faster than calling long.ToString() on x64 + // and ~600% faster than calling long.ToString() on x86 in tight loops of 1 million+ iterations + // See: https://github.com/aspnet/Hosting/pull/385 + + // stackalloc to allocate array on stack rather than heap + char* charBuffer = stackalloc char[13]; + + charBuffer[0] = _encode32Chars[(int)(id >> 60) & 31]; + charBuffer[1] = _encode32Chars[(int)(id >> 55) & 31]; + charBuffer[2] = _encode32Chars[(int)(id >> 50) & 31]; + charBuffer[3] = _encode32Chars[(int)(id >> 45) & 31]; + charBuffer[4] = _encode32Chars[(int)(id >> 40) & 31]; + charBuffer[5] = _encode32Chars[(int)(id >> 35) & 31]; + charBuffer[6] = _encode32Chars[(int)(id >> 30) & 31]; + charBuffer[7] = _encode32Chars[(int)(id >> 25) & 31]; + charBuffer[8] = _encode32Chars[(int)(id >> 20) & 31]; + charBuffer[9] = _encode32Chars[(int)(id >> 15) & 31]; + charBuffer[10] = _encode32Chars[(int)(id >> 10) & 31]; + charBuffer[11] = _encode32Chars[(int)(id >> 5) & 31]; + charBuffer[12] = _encode32Chars[(int)id & 31]; + + // string ctor overload that takes char* + return new string(charBuffer, 0, 13); + } + private enum ConnectionState { CreatingFrame, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs index 3a624d3659..bea3e7c7a5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/ConnectionContext.cs @@ -1,6 +1,10 @@ // 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.Net; +using Microsoft.AspNetCore.Http.Features; + namespace Microsoft.AspNetCore.Server.Kestrel.Http { public class ConnectionContext : ListenerContext @@ -18,10 +22,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http SocketInput = context.SocketInput; SocketOutput = context.SocketOutput; ConnectionControl = context.ConnectionControl; + RemoteEndPoint = context.RemoteEndPoint; + LocalEndPoint = context.LocalEndPoint; + ConnectionId = context.ConnectionId; + PrepareRequest = context.PrepareRequest; } public SocketInput SocketInput { get; set; } + public ISocketOutput SocketOutput { get; set; } + public IConnectionControl ConnectionControl { get; set; } + + public IPEndPoint RemoteEndPoint { get; set; } + + public IPEndPoint LocalEndPoint { get; set; } + + public string ConnectionId { get; set; } + + public Action PrepareRequest { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index a1d03fd2b1..827398ba0c 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -272,6 +272,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http int IHttpConnectionFeature.LocalPort { get; set; } + string IHttpConnectionFeature.ConnectionId { get; set; } + object IFeatureCollection.this[Type key] { get { return FastFeatureGet(key); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index c830fcc2ee..2c83fc7c84 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -67,26 +67,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private HttpVersionType _httpVersion; - private readonly IPEndPoint _localEndPoint; - private readonly IPEndPoint _remoteEndPoint; - private readonly Action _prepareRequest; - private readonly string _pathBase; public Frame(ConnectionContext context) - : this(context, remoteEndPoint: null, localEndPoint: null, prepareRequest: null) - { - } - - public Frame(ConnectionContext context, - IPEndPoint remoteEndPoint, - IPEndPoint localEndPoint, - Action prepareRequest) : base(context) { - _remoteEndPoint = remoteEndPoint; - _localEndPoint = localEndPoint; - _prepareRequest = prepareRequest; _pathBase = context.ServerAddress.PathBase; FrameControl = this; @@ -249,13 +234,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http ReasonPhrase = null; var httpConnectionFeature = this as IHttpConnectionFeature; - httpConnectionFeature.RemoteIpAddress = _remoteEndPoint?.Address; - httpConnectionFeature.RemotePort = _remoteEndPoint?.Port ?? 0; + httpConnectionFeature.RemoteIpAddress = RemoteEndPoint?.Address; + httpConnectionFeature.RemotePort = RemoteEndPoint?.Port ?? 0; - httpConnectionFeature.LocalIpAddress = _localEndPoint?.Address; - httpConnectionFeature.LocalPort = _localEndPoint?.Port ?? 0; + httpConnectionFeature.LocalIpAddress = LocalEndPoint?.Address; + httpConnectionFeature.LocalPort = LocalEndPoint?.Port ?? 0; - _prepareRequest?.Invoke(this); + httpConnectionFeature.ConnectionId = ConnectionId; + + PrepareRequest?.Invoke(this); _manuallySetRequestAbortToken = null; _abortedCts = null; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 1c54363146..77e7c4047b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -17,16 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public Frame(IHttpApplication application, ConnectionContext context) - : this(application, context, remoteEndPoint: null, localEndPoint: null, prepareRequest: null) - { - } - - public Frame(IHttpApplication application, - ConnectionContext context, - IPEndPoint remoteEndPoint, - IPEndPoint localEndPoint, - Action prepareRequest) - : base(context, remoteEndPoint, localEndPoint, prepareRequest) + : base(context) { _application = application; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs index 6e9e4bebf1..8804d0255f 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketOutput.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private readonly KestrelThread _thread; private readonly UvStreamHandle _socket; private readonly Connection _connection; - private readonly long _connectionId; + private readonly string _connectionId; private readonly IKestrelTrace _log; private readonly IThreadPool _threadPool; @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http UvStreamHandle socket, MemoryPool2 memory, Connection connection, - long connectionId, + string connectionId, IKestrelTrace log, IThreadPool threadPool, Queue writeReqPool) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs index 26af1717c2..b004cb9eee 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IKestrelTrace.cs @@ -5,33 +5,33 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { public interface IKestrelTrace : ILogger { - void ConnectionStart(long connectionId); + void ConnectionStart(string connectionId); - void ConnectionStop(long connectionId); + void ConnectionStop(string connectionId); - void ConnectionRead(long connectionId, int count); + void ConnectionRead(string connectionId, int count); - void ConnectionPause(long connectionId); + void ConnectionPause(string connectionId); - void ConnectionResume(long connectionId); + void ConnectionResume(string connectionId); - void ConnectionReadFin(long connectionId); + void ConnectionReadFin(string connectionId); - void ConnectionWriteFin(long connectionId); + void ConnectionWriteFin(string connectionId); - void ConnectionWroteFin(long connectionId, int status); + void ConnectionWroteFin(string connectionId, int status); - void ConnectionKeepAlive(long connectionId); + void ConnectionKeepAlive(string connectionId); - void ConnectionDisconnect(long connectionId); + void ConnectionDisconnect(string connectionId); - void ConnectionWrite(long connectionId, int count); + void ConnectionWrite(string connectionId, int count); - void ConnectionWriteCallback(long connectionId, int status); + void ConnectionWriteCallback(string connectionId, int status); - void ConnectionError(long connectionId, Exception ex); + void ConnectionError(string connectionId, Exception ex); - void ConnectionDisconnectedWrite(long connectionId, int count, Exception ex); + void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex); void NotAllConnectionsClosedGracefully(); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs index 0edcd183fb..3c92c771ef 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/KestrelTrace.cs @@ -12,38 +12,38 @@ namespace Microsoft.AspNetCore.Server.Kestrel /// public class KestrelTrace : IKestrelTrace { - private static readonly Action _connectionStart; - private static readonly Action _connectionStop; - private static readonly Action _connectionPause; - private static readonly Action _connectionResume; - private static readonly Action _connectionReadFin; - private static readonly Action _connectionWriteFin; - private static readonly Action _connectionWroteFin; - private static readonly Action _connectionKeepAlive; - private static readonly Action _connectionDisconnect; - private static readonly Action _connectionError; - private static readonly Action _connectionDisconnectedWrite; + private static readonly Action _connectionStart; + private static readonly Action _connectionStop; + private static readonly Action _connectionPause; + private static readonly Action _connectionResume; + private static readonly Action _connectionReadFin; + private static readonly Action _connectionWriteFin; + private static readonly Action _connectionWroteFin; + private static readonly Action _connectionKeepAlive; + private static readonly Action _connectionDisconnect; + private static readonly Action _connectionError; + private static readonly Action _connectionDisconnectedWrite; private static readonly Action _notAllConnectionsClosedGracefully; protected readonly ILogger _logger; static KestrelTrace() { - _connectionStart = LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); - _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); + _connectionStart = LoggerMessage.Define(LogLevel.Debug, 1, @"Connection id ""{ConnectionId}"" started."); + _connectionStop = LoggerMessage.Define(LogLevel.Debug, 2, @"Connection id ""{ConnectionId}"" stopped."); // ConnectionRead: Reserved: 3 - _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); - _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); - _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); - _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); - _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); - _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); - _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); + _connectionPause = LoggerMessage.Define(LogLevel.Debug, 4, @"Connection id ""{ConnectionId}"" paused."); + _connectionResume = LoggerMessage.Define(LogLevel.Debug, 5, @"Connection id ""{ConnectionId}"" resumed."); + _connectionReadFin = LoggerMessage.Define(LogLevel.Debug, 6, @"Connection id ""{ConnectionId}"" received FIN."); + _connectionWriteFin = LoggerMessage.Define(LogLevel.Debug, 7, @"Connection id ""{ConnectionId}"" sending FIN."); + _connectionWroteFin = LoggerMessage.Define(LogLevel.Debug, 8, @"Connection id ""{ConnectionId}"" sent FIN with status ""{Status}""."); + _connectionKeepAlive = LoggerMessage.Define(LogLevel.Debug, 9, @"Connection id ""{ConnectionId}"" completed keep alive response."); + _connectionDisconnect = LoggerMessage.Define(LogLevel.Debug, 10, @"Connection id ""{ConnectionId}"" disconnecting."); // ConnectionWrite: Reserved: 11 // ConnectionWriteCallback: Reserved: 12 // ApplicationError: Reserved: 13 - LoggerMessage.Define overload not present - _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); - _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); + _connectionError = LoggerMessage.Define(LogLevel.Information, 14, @"Connection id ""{ConnectionId}"" communication error"); + _connectionDisconnectedWrite = LoggerMessage.Define(LogLevel.Debug, 15, @"Connection id ""{ConnectionId}"" write of ""{count}"" bytes to disconnected client."); _notAllConnectionsClosedGracefully = LoggerMessage.Define(LogLevel.Debug, 16, "Some connections failed to close gracefully during server shutdown."); } @@ -52,64 +52,64 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger = logger; } - public virtual void ConnectionStart(long connectionId) + public virtual void ConnectionStart(string connectionId) { _connectionStart(_logger, connectionId, null); } - public virtual void ConnectionStop(long connectionId) + public virtual void ConnectionStop(string connectionId) { _connectionStop(_logger, connectionId, null); } - public virtual void ConnectionRead(long connectionId, int count) + 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(long connectionId) + public virtual void ConnectionPause(string connectionId) { _connectionPause(_logger, connectionId, null); } - public virtual void ConnectionResume(long connectionId) + public virtual void ConnectionResume(string connectionId) { _connectionResume(_logger, connectionId, null); } - public virtual void ConnectionReadFin(long connectionId) + public virtual void ConnectionReadFin(string connectionId) { _connectionReadFin(_logger, connectionId, null); } - public virtual void ConnectionWriteFin(long connectionId) + public virtual void ConnectionWriteFin(string connectionId) { _connectionWriteFin(_logger, connectionId, null); } - public virtual void ConnectionWroteFin(long connectionId, int status) + public virtual void ConnectionWroteFin(string connectionId, int status) { _connectionWroteFin(_logger, connectionId, status, null); } - public virtual void ConnectionKeepAlive(long connectionId) + public virtual void ConnectionKeepAlive(string connectionId) { _connectionKeepAlive(_logger, connectionId, null); } - public virtual void ConnectionDisconnect(long connectionId) + public virtual void ConnectionDisconnect(string connectionId) { _connectionDisconnect(_logger, connectionId, null); } - public virtual void ConnectionWrite(long connectionId, int count) + 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(long connectionId, int status) + public virtual void ConnectionWriteCallback(string connectionId, int status) { // Don't log for now since this could be *too* verbose. // Reserved: Event ID 12 @@ -120,12 +120,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel _logger.LogError(13, ex, "An unhandled exception was thrown by the application."); } - public virtual void ConnectionError(long connectionId, Exception ex) + public virtual void ConnectionError(string connectionId, Exception ex) { _connectionError(_logger, connectionId, ex); } - public virtual void ConnectionDisconnectedWrite(long connectionId, int count, Exception ex) + public virtual void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) { _connectionDisconnectedWrite(_logger, connectionId, count, ex); } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs index ead9f9b2da..6d38e3e2b5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/KestrelServer.cs @@ -59,9 +59,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel var trace = new KestrelTrace(_logger); var engine = new KestrelEngine(new ServiceContext { - FrameFactory = (context, remoteEP, localEP, prepareRequest) => + FrameFactory = context => { - return new Frame(application, context, remoteEP, localEP, prepareRequest); + return new Frame(application, context); }, AppLifetime = _applicationLifetime, Log = trace, diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs index f702fd1c5e..a591a671ff 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/ServiceContext.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel public IThreadPool ThreadPool { get; set; } - public Func, Frame> FrameFactory { get; set; } + public Func FrameFactory { get; set; } public DateHeaderValueManager DateHeaderValueManager { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs index 7162cd0f70..8fa09e4866 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/SocketOutputTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); // I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test. var bufferSize = 1048576; @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted / 2; var data = new byte[bufferSize]; @@ -237,7 +237,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var mockConnection = new MockConnection()) { - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; @@ -348,7 +348,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests using (var mockConnection = new MockConnection()) { var abortedSource = mockConnection.RequestAbortedSource; - ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, 0, trace, ltp, new Queue()); + ISocketOutput socketOutput = new SocketOutput(kestrelThread, socket, memory, mockConnection, "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; @@ -432,7 +432,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); var bufferSize = maxBytesPreCompleted; var buffer = new ArraySegment(new byte[bufferSize], 0, bufferSize); @@ -518,7 +518,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests var socket = new MockSocket(kestrelThread.Loop.ThreadId, new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), 0, trace, ltp, new Queue()); + var socketOutput = new SocketOutput(kestrelThread, socket, memory, new MockConnection(), "0", trace, ltp, new Queue()); // block 1 var start = socketOutput.ProducingStart(); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs index eead43b301..11076560bc 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestLogger.cs @@ -11,17 +11,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } - public override void ConnectionRead(long connectionId, int count) + public override void ConnectionRead(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" recv {count} bytes.", connectionId, count); } - public override void ConnectionWrite(long connectionId, int count) + public override void ConnectionWrite(string connectionId, int count) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send {count} bytes.", connectionId, count); } - public override void ConnectionWriteCallback(long connectionId, int status) + public override void ConnectionWriteCallback(string connectionId, int status) { //_logger.LogDebug(1, @"Connection id ""{ConnectionId}"" send finished with status {status}.", connectionId, status); } diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs index 1c0ff5dd1e..6a84a29fd5 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServer.cs @@ -39,9 +39,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests public void Create(RequestDelegate app, ServiceContext context, string serverAddress) { - context.FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) => + context.FrameFactory = connectionContext => { - return new Frame(new DummyApplication(app), connectionContext, remoteEP, localEP, prepareRequest); + return new Frame(new DummyApplication(app), connectionContext); }; _engine = new KestrelEngine(context); _engine.Start(1); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs index 743044c2eb..ff08f19714 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestServiceContext.cs @@ -44,9 +44,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests set { _app = value; - FrameFactory = (connectionContext, remoteEP, localEP, prepareRequest) => + FrameFactory = connectionContext => { - return new Frame(new DummyApplication(_app), connectionContext, remoteEP, localEP, prepareRequest); + return new Frame(new DummyApplication(_app), connectionContext); }; } }