Bypass LibuvStream if no ConnectionFilter wraps it

This commit is contained in:
Stephen Halter 2016-01-13 10:42:42 -08:00
parent e5ad019575
commit 129a5ad474
3 changed files with 27 additions and 8 deletions

View File

@ -5,5 +5,6 @@ using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]

View File

@ -23,6 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private readonly UvStreamHandle _socket;
private Frame _frame;
private ConnectionFilterContext _filterContext;
private LibuvStream _libuvStream;
private readonly long _connectionId;
private readonly SocketInput _rawSocketInput;
@ -70,11 +71,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}
else
{
var libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput);
_libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput);
_filterContext = new ConnectionFilterContext
{
Connection = libuvStream,
Connection = _libuvStream,
Address = ServerAddress
};
@ -124,10 +125,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private void ApplyConnectionFilter()
{
var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool);
if (_filterContext.Connection != _libuvStream)
{
var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool);
SocketInput = filteredStreamAdapter.SocketInput;
SocketOutput = filteredStreamAdapter.SocketOutput;
SocketInput = filteredStreamAdapter.SocketInput;
SocketOutput = filteredStreamAdapter.SocketOutput;
}
else
{
SocketInput = _rawSocketInput;
SocketOutput = _rawSocketOutput;
}
_frame = CreateFrame();
_frame.Start();

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.Linq;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
@ -13,7 +13,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Server.Kestrel;
using Microsoft.AspNet.Server.Kestrel.Filter;
using Microsoft.AspNet.Server.Kestrel.Http;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Testing.xunit;
using Microsoft.Extensions.Logging;
using Xunit;
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
{
new TestServiceContext
{
ConnectionFilter = new NoOpConnectionFilter()
ConnectionFilter = new PassThroughConnectionFilter()
}
}
};
@ -1177,5 +1177,14 @@ namespace Microsoft.AspNet.Server.KestrelTests
}
}
}
private class PassThroughConnectionFilter : IConnectionFilter
{
public Task OnConnectionAsync(ConnectionFilterContext context)
{
context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger());
return TaskUtilities.CompletedTask;
}
}
}
}