Updating Darwin OS detection
This commit is contained in:
parent
dcf55abc9f
commit
e550d1f1ec
|
|
@ -44,19 +44,19 @@ 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,
|
||||
"native",
|
||||
"native",
|
||||
"darwin",
|
||||
"universal",
|
||||
"universal",
|
||||
"libuv.dylib");
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryPath = "libuv.so.1";
|
||||
}
|
||||
}
|
||||
Libuv.Load(libraryPath);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
|||
{
|
||||
public static class PlatformApis
|
||||
{
|
||||
public static bool IsWindows()
|
||||
public static bool IsWindows()
|
||||
{
|
||||
#if ASPNETCORE50
|
||||
return true;
|
||||
|
|
@ -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)
|
||||
|
|
@ -55,7 +83,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
|||
{
|
||||
[DllImport("libdl")]
|
||||
public static extern IntPtr dlopen(String fileName, int flags);
|
||||
|
||||
|
||||
[DllImport("libdl")]
|
||||
public static extern IntPtr dlsym(IntPtr handle, String symbol);
|
||||
|
||||
|
|
@ -65,17 +93,17 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
|
|||
[DllImport("libdl")]
|
||||
public static extern IntPtr dlerror();
|
||||
|
||||
public static IntPtr LoadLibrary(string dllToLoad)
|
||||
public static IntPtr LoadLibrary(string dllToLoad)
|
||||
{
|
||||
return dlopen(dllToLoad, 2);
|
||||
}
|
||||
|
||||
public static bool FreeLibrary(IntPtr hModule)
|
||||
public static bool FreeLibrary(IntPtr hModule)
|
||||
{
|
||||
return dlclose(hModule) == 0;
|
||||
}
|
||||
|
||||
public static IntPtr GetProcAddress(IntPtr hModule, string procedureName)
|
||||
public static IntPtr GetProcAddress(IntPtr hModule, string procedureName)
|
||||
{
|
||||
dlerror();
|
||||
var res = dlsym(hModule, procedureName);
|
||||
|
|
|
|||
Loading…
Reference in New Issue