Fix byte[] array allocation in IsDarwin
This commit is contained in:
parent
a3a49d21b8
commit
2e2dfd87c1
|
|
@ -10,11 +10,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
||||||
{
|
{
|
||||||
public Libuv()
|
public Libuv()
|
||||||
{
|
{
|
||||||
IsWindows = PlatformApis.IsWindows();
|
IsWindows = PlatformApis.IsWindows;
|
||||||
|
|
||||||
var isDarwinMono =
|
var isDarwinMono =
|
||||||
#if DNX451
|
#if DNX451
|
||||||
IsWindows ? false : PlatformApis.IsDarwin();
|
IsWindows ? false : PlatformApis.IsDarwin;
|
||||||
#else
|
#else
|
||||||
false;
|
false;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,25 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
||||||
{
|
{
|
||||||
public static class PlatformApis
|
public static class PlatformApis
|
||||||
{
|
{
|
||||||
public static bool IsWindows()
|
static PlatformApis()
|
||||||
{
|
{
|
||||||
#if DOTNET5_4 || DNXCORE50
|
#if DOTNET5_4 || DNXCORE50
|
||||||
// Until Environment.OSVersion.Platform is exposed on .NET Core, we
|
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
// try to call uname and if that fails we assume we are on Windows.
|
IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||||
return GetUname() == string.Empty;
|
|
||||||
#else
|
#else
|
||||||
var p = (int)Environment.OSVersion.Platform;
|
var p = (int)System.Environment.OSVersion.Platform;
|
||||||
return (p != 4) && (p != 6) && (p != 128);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsWindows { get; }
|
||||||
|
|
||||||
public static bool IsDarwin()
|
public static bool IsDarwin { get; }
|
||||||
{
|
|
||||||
return string.Equals(GetUname(), "Darwin", StringComparison.Ordinal);
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport("libc")]
|
[DllImport("libc")]
|
||||||
static extern int uname(IntPtr buf);
|
static extern int uname(IntPtr buf);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
||||||
var port = ((int)(_field0 & 0x00FF0000) >> 8) | (int)((_field0 & 0xFF000000) >> 24);
|
var port = ((int)(_field0 & 0x00FF0000) >> 8) | (int)((_field0 & 0xFF000000) >> 24);
|
||||||
|
|
||||||
int family = (int)_field0;
|
int family = (int)_field0;
|
||||||
if (PlatformApis.IsDarwin())
|
if (PlatformApis.IsDarwin)
|
||||||
{
|
{
|
||||||
// see explaination in example 4
|
// see explaination in example 4
|
||||||
family = family >> 8;
|
family = family >> 8;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue