Fix byte[] array allocation in IsDarwin

This commit is contained in:
Troy Dai 2015-11-13 21:40:17 -08:00
parent a3a49d21b8
commit 2e2dfd87c1
3 changed files with 16 additions and 14 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;