Updating Darwin OS detection

This commit is contained in:
Louis DeJardin 2014-10-20 16:11:48 -07:00
parent dcf55abc9f
commit e550d1f1ec
3 changed files with 46 additions and 12 deletions

View File

@ -44,11 +44,7 @@ namespace Microsoft.AspNet.Server.Kestrel
architecture, architecture,
"libuv.dll"); "libuv.dll");
} }
else if ((int)Environment.OSVersion.Platform == 4) else if (Libuv.IsDarwin)
{
libraryPath = "libuv.so.1";
}
else
{ {
libraryPath = Path.Combine( libraryPath = Path.Combine(
libraryPath, libraryPath,
@ -57,6 +53,10 @@ namespace Microsoft.AspNet.Server.Kestrel
"universal", "universal",
"libuv.dylib"); "libuv.dylib");
} }
else
{
libraryPath = "libuv.so.1";
}
} }
Libuv.Load(libraryPath); Libuv.Load(libraryPath);
} }

View File

@ -13,9 +13,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
public Libuv() public Libuv()
{ {
IsWindows = PlatformApis.IsWindows(); IsWindows = PlatformApis.IsWindows();
if (!IsWindows)
{
IsDarwin = PlatformApis.IsDarwin();
}
} }
public bool IsWindows; public bool IsWindows;
public bool IsDarwin;
public Func<string, IntPtr> LoadLibrary; public Func<string, IntPtr> LoadLibrary;
public Func<IntPtr, bool> FreeLibrary; public Func<IntPtr, bool> FreeLibrary;
public Func<IntPtr, string, IntPtr> GetProcAddress; public Func<IntPtr, string, IntPtr> GetProcAddress;

View File

@ -20,6 +20,34 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
#endif #endif
} }
[DllImport("libc")]
static extern int uname(IntPtr buf);
static unsafe string GetUname()
{
var buffer = new byte[8192];
try
{
fixed (byte* buf = buffer)
{
if (uname((IntPtr)buf) == 0)
{
return Marshal.PtrToStringAnsi((IntPtr)buf);
}
}
return string.Empty;
}
catch
{
return string.Empty;
}
}
public static bool IsDarwin()
{
return string.Equals(GetUname(), "Darwin", StringComparison.Ordinal);
}
public static void Apply(Libuv libuv) public static void Apply(Libuv libuv)
{ {
if (libuv.IsWindows) if (libuv.IsWindows)