Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 6b25ee7

Browse files
committed
Replace PlatformAbstractions with RuntimeInformation
1 parent 50e140d commit 6b25ee7

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.Extensions.PlatformAbstractions;
4+
using System.Runtime.InteropServices;
55

66
namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure
77
{
@@ -28,32 +28,36 @@ internal class Constants
2828

2929
private static int? GetECONNRESET()
3030
{
31-
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
31+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3232
{
33-
case Platform.Windows:
34-
return -4077;
35-
case Platform.Linux:
36-
return -104;
37-
case Platform.Darwin:
38-
return -54;
39-
default:
40-
return null;
33+
return -4077;
4134
}
35+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
36+
{
37+
return -104;
38+
}
39+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
40+
{
41+
return -54;
42+
}
43+
return null;
4244
}
4345

4446
private static int? GetEADDRINUSE()
4547
{
46-
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
48+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
49+
{
50+
return -4091;
51+
}
52+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
53+
{
54+
return -98;
55+
}
56+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
4757
{
48-
case Platform.Windows:
49-
return -4091;
50-
case Platform.Linux:
51-
return -98;
52-
case Platform.Darwin:
53-
return -48;
54-
default:
55-
return null;
58+
return -48;
5659
}
60+
return null;
5761
}
5862
}
5963
}

src/Microsoft.AspNetCore.Server.Kestrel/Networking/PlatformApis.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,15 @@
33

44
using System;
55
using System.Runtime.InteropServices;
6-
using Microsoft.Extensions.PlatformAbstractions;
76

87
namespace Microsoft.AspNetCore.Server.Kestrel.Networking
98
{
109
public static class PlatformApis
1110
{
1211
static PlatformApis()
1312
{
14-
#if NETSTANDARD1_3
1513
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
1614
IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
17-
#else
18-
var p = (int)Environment.OSVersion.Platform;
19-
IsWindows = (p != 4) && (p != 6) && (p != 128);
20-
21-
if (!IsWindows)
22-
{
23-
// When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead.
24-
IsDarwin = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Darwin;
25-
}
26-
#endif
2715
}
2816

2917
public static bool IsWindows { get; }

src/Microsoft.AspNetCore.Server.Kestrel/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"dependencies": {
1515
"System.Buffers": "4.0.0-*",
1616
"System.Numerics.Vectors": "4.1.1-*",
17+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*",
1718
"System.Threading.Tasks.Extensions": "4.0.0-*",
1819
"Libuv": "1.9.0-*",
1920
"Microsoft.AspNetCore.Hosting": "1.0.0-*",
20-
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
21-
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*"
21+
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*"
2222
},
2323
"frameworks": {
2424
"net451": {

0 commit comments

Comments
 (0)