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

View File

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

View File

@ -20,6 +20,34 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
#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)
{
if (libuv.IsWindows)