Remove TCP Loopback Fast Path code (#1147).
This commit is contained in:
parent
ffc3eb3afd
commit
bf94f8526a
|
|
@ -199,40 +199,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking
|
|||
{
|
||||
handle.Validate();
|
||||
ThrowIfErrored(_uv_tcp_bind(handle, ref addr, flags));
|
||||
if (PlatformApis.IsWindows)
|
||||
{
|
||||
tcp_bind_windows_extras(handle);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe void tcp_bind_windows_extras(UvTcpHandle handle)
|
||||
{
|
||||
const int SIO_LOOPBACK_FAST_PATH = -1744830448; // IOC_IN | IOC_WS2 | 16;
|
||||
const int WSAEOPNOTSUPP = 10000 + 45; // (WSABASEERR+45)
|
||||
const int SOCKET_ERROR = -1;
|
||||
|
||||
var socket = IntPtr.Zero;
|
||||
ThrowIfErrored(_uv_fileno(handle, ref socket));
|
||||
|
||||
// Enable loopback fast-path for lower latency for localhost comms, like HttpPlatformHandler fronting
|
||||
// http://blogs.technet.com/b/wincat/archive/2012/12/05/fast-tcp-loopback-performance-and-low-latency-with-windows-server-2012-tcp-loopback-fast-path.aspx
|
||||
// https://github.com/libuv/libuv/issues/489
|
||||
var optionValue = 1;
|
||||
uint dwBytes = 0u;
|
||||
|
||||
var result = NativeMethods.WSAIoctl(socket, SIO_LOOPBACK_FAST_PATH, &optionValue, sizeof(int), null, 0, out dwBytes, IntPtr.Zero, IntPtr.Zero);
|
||||
if (result == SOCKET_ERROR)
|
||||
{
|
||||
var errorId = NativeMethods.WSAGetLastError();
|
||||
if (errorId == WSAEOPNOTSUPP)
|
||||
{
|
||||
// This system is not >= Windows Server 2012, and the call is not supported.
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowIfErrored(errorId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Func<UvTcpHandle, IntPtr, int> _uv_tcp_open;
|
||||
|
|
|
|||
|
|
@ -471,10 +471,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
// Use Send instead of SendEnd to ensure the connection will remain open while
|
||||
// the app runs and reads 0 bytes from the body nonetheless. This checks that
|
||||
// https://github.com/aspnet/KestrelHttpServer/issues/1104 is not regressing.
|
||||
await connection.Send(
|
||||
await connection.SendEnd(
|
||||
"GET / HTTP/1.1",
|
||||
"Connection: close",
|
||||
"",
|
||||
|
|
@ -490,7 +487,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
await connection.Send(
|
||||
await connection.SendEnd(
|
||||
"GET / HTTP/1.0",
|
||||
"",
|
||||
"");
|
||||
|
|
@ -577,6 +574,51 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ConnectionFilterData))]
|
||||
public async Task ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader(TestServiceContext testContext)
|
||||
{
|
||||
using (var server = new TestServer(async httpContext =>
|
||||
{
|
||||
Assert.Equal(0, await httpContext.Request.Body.ReadAsync(new byte[1], 0, 1).TimeoutAfter(TimeSpan.FromSeconds(10)));
|
||||
}, testContext))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
// Use Send instead of SendEnd to ensure the connection will remain open while
|
||||
// the app runs and reads 0 bytes from the body nonetheless. This checks that
|
||||
// https://github.com/aspnet/KestrelHttpServer/issues/1104 is not regressing.
|
||||
await connection.Send(
|
||||
"GET / HTTP/1.1",
|
||||
"Connection: close",
|
||||
"",
|
||||
"a");
|
||||
await connection.ReceiveEnd(
|
||||
"HTTP/1.1 200 OK",
|
||||
"Connection: close",
|
||||
$"Date: {testContext.DateHeaderValue}",
|
||||
"Content-Length: 0",
|
||||
"",
|
||||
"");
|
||||
}
|
||||
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
await connection.Send(
|
||||
"GET / HTTP/1.0",
|
||||
"",
|
||||
"a");
|
||||
await connection.ReceiveEnd(
|
||||
"HTTP/1.1 200 OK",
|
||||
"Connection: close",
|
||||
$"Date: {testContext.DateHeaderValue}",
|
||||
"Content-Length: 0",
|
||||
"",
|
||||
"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ConnectionFilterData))]
|
||||
public async Task ConnectionClosedAfter101Response(TestServiceContext testContext)
|
||||
|
|
|
|||
|
|
@ -167,21 +167,6 @@ namespace Microsoft.AspNetCore.Testing
|
|||
public static Socket CreateConnectedLoopbackSocket(int port)
|
||||
{
|
||||
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
if (PlatformApis.IsWindows)
|
||||
{
|
||||
const int SIO_LOOPBACK_FAST_PATH = -1744830448;
|
||||
var optionInValue = BitConverter.GetBytes(1);
|
||||
try
|
||||
{
|
||||
socket.IOControl(SIO_LOOPBACK_FAST_PATH, optionInValue, null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If the operating system version on this machine did
|
||||
// not support SIO_LOOPBACK_FAST_PATH (i.e. version
|
||||
// prior to Windows 8 / Windows Server 2012), handle the exception
|
||||
}
|
||||
}
|
||||
socket.Connect(new IPEndPoint(IPAddress.Loopback, port));
|
||||
return socket;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue