From 0a21b9460955b89bda68d08978709ca81298e81b Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 21 Apr 2016 16:17:09 -0700 Subject: [PATCH] Make ECONNRESET value platform-specific (#649). --- .../Http/Connection.cs | 8 ++++++++ .../Infrastructure/Constants.cs | 20 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index 4c0668698a..814da8143b 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -40,6 +40,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http private ConnectionState _connectionState; private TaskCompletionSource _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); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs index 098db13c79..dcbd4cb5f3 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/Constants.cs @@ -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(); /// /// 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. /// 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; + } + } } }