diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index ef6fb74434..f00bfa586e 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -10,11 +10,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public Libuv() { - IsWindows = PlatformApis.IsWindows(); + IsWindows = PlatformApis.IsWindows; var isDarwinMono = #if DNX451 - IsWindows ? false : PlatformApis.IsDarwin(); + IsWindows ? false : PlatformApis.IsDarwin; #else false; #endif diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs index f874ac9b15..370fcb30c2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/PlatformApis.cs @@ -8,23 +8,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public static class PlatformApis { - public static bool IsWindows() + static PlatformApis() { #if DOTNET5_4 || DNXCORE50 - // Until Environment.OSVersion.Platform is exposed on .NET Core, we - // try to call uname and if that fails we assume we are on Windows. - return GetUname() == string.Empty; + IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); #else - var p = (int)Environment.OSVersion.Platform; - return (p != 4) && (p != 6) && (p != 128); + var p = (int)System.Environment.OSVersion.Platform; + IsWindows = (p != 4) && (p != 6) && (p != 128); + + // When running on Mono in Darwin OSVersion doesn't return Darwin. It returns Unix instead. + // Fallback to use uname. + IsDarwin = string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); #endif } + + public static bool IsWindows { get; } - public static bool IsDarwin() - { - return string.Equals(GetUname(), "Darwin", StringComparison.Ordinal); - } - + public static bool IsDarwin { get; } + [DllImport("libc")] static extern int uname(IntPtr buf); diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs index 3be4ee9301..762b1f5140 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/SockAddr.cs @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking var port = ((int)(_field0 & 0x00FF0000) >> 8) | (int)((_field0 & 0xFF000000) >> 24); int family = (int)_field0; - if (PlatformApis.IsDarwin()) + if (PlatformApis.IsDarwin) { // see explaination in example 4 family = family >> 8;