Make ECONNRESET value platform-specific (#649).

This commit is contained in:
Cesar Blum Silveira 2016-04-21 16:17:09 -07:00
parent 179b57b01f
commit 0a21b94609
2 changed files with 27 additions and 1 deletions

View File

@ -40,6 +40,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
private ConnectionState _connectionState;
private TaskCompletionSource<object> _socketClosedTcs;
bool _eConnResetChecked = false;
public Connection(ListenerContext context, UvStreamHandle socket) : base(context)
{
_socket = socket;
@ -272,6 +274,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
return;
}
if (!_eConnResetChecked && !Constants.ECONNRESET.HasValue)
{
Log.LogWarning("Unable to determine ECONNRESET value on this platform.");
_eConnResetChecked = true;
}
var normalRead = status > 0;
var normalDone = status == Constants.ECONNRESET || status == Constants.EOF;
var errorDone = !(normalDone || normalRead);

View File

@ -1,6 +1,9 @@
// 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.PlatformAbstractions;
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
{
internal class Constants
@ -8,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
public const int ListenBacklog = 128;
public const int EOF = -4095;
public const int ECONNRESET = -4077;
public static readonly int? ECONNRESET = GetECONNRESET();
/// <summary>
/// Prefix of host name used to specify Unix sockets in the configuration.
@ -20,5 +23,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
/// for info on the format.
/// </summary>
public const string RFC1123DateFormat = "r";
private static int? GetECONNRESET()
{
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
{
case Platform.Windows:
return -4077;
case Platform.Linux:
return -104;
case Platform.Darwin:
return -54;
default:
return null;
}
}
}
}