Replace PlatformAbstractions with RuntimeInformation
This commit is contained in:
parent
50e140da43
commit
6b25ee7343
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
{
|
{
|
||||||
|
|
@ -28,32 +28,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
|
||||||
|
|
||||||
private static int? GetECONNRESET()
|
private static int? GetECONNRESET()
|
||||||
{
|
{
|
||||||
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
case Platform.Windows:
|
return -4077;
|
||||||
return -4077;
|
|
||||||
case Platform.Linux:
|
|
||||||
return -104;
|
|
||||||
case Platform.Darwin:
|
|
||||||
return -54;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
{
|
||||||
|
return -104;
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
return -54;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int? GetEADDRINUSE()
|
private static int? GetEADDRINUSE()
|
||||||
{
|
{
|
||||||
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
case Platform.Windows:
|
return -4091;
|
||||||
return -4091;
|
|
||||||
case Platform.Linux:
|
|
||||||
return -98;
|
|
||||||
case Platform.Darwin:
|
|
||||||
return -48;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
{
|
||||||
|
return -98;
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
return -48;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Networking
|
namespace Microsoft.AspNetCore.Server.Kestrel.Networking
|
||||||
{
|
{
|
||||||
|
|
@ -11,19 +10,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Networking
|
||||||
{
|
{
|
||||||
static PlatformApis()
|
static PlatformApis()
|
||||||
{
|
{
|
||||||
#if NETSTANDARD1_3
|
|
||||||
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||||
#else
|
|
||||||
var p = (int)Environment.OSVersion.Platform;
|
|
||||||
IsWindows = (p != 4) && (p != 6) && (p != 128);
|
|
||||||
|
|
||||||
if (!IsWindows)
|
|
||||||
{
|
|
||||||
// When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead.
|
|
||||||
IsDarwin = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Darwin;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsWindows { get; }
|
public static bool IsWindows { get; }
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.Buffers": "4.0.0-*",
|
"System.Buffers": "4.0.0-*",
|
||||||
"System.Numerics.Vectors": "4.1.1-*",
|
"System.Numerics.Vectors": "4.1.1-*",
|
||||||
|
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*",
|
||||||
"System.Threading.Tasks.Extensions": "4.0.0-*",
|
"System.Threading.Tasks.Extensions": "4.0.0-*",
|
||||||
"Libuv": "1.9.0-*",
|
"Libuv": "1.9.0-*",
|
||||||
"Microsoft.AspNetCore.Hosting": "1.0.0-*",
|
"Microsoft.AspNetCore.Hosting": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
|
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*"
|
||||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*"
|
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": {
|
"net451": {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue