Refactor: Create Netch.Interops namespace

This commit is contained in:
ChsBuffer
2021-03-28 00:54:04 +08:00
parent 090e487733
commit b553ddbb71
9 changed files with 53 additions and 47 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using static Netch.Interops.AioDNSInterops;
namespace Netch.Controllers
{
@@ -11,7 +10,7 @@ namespace Netch.Controllers
public void Stop()
{
aiodns_free();
Free();
}
/// <summary>
@@ -20,36 +19,14 @@ namespace Netch.Controllers
/// <returns></returns>
public void Start()
{
aiodns_dial((int) NameList.TYPE_REST, null);
aiodns_dial((int) NameList.TYPE_ADDR, Encoding.UTF8.GetBytes($"{Global.Settings.LocalAddress}:{Global.Settings.AioDNS.ListenPort}"));
aiodns_dial((int) NameList.TYPE_LIST, Encoding.UTF8.GetBytes(Path.GetFullPath(Global.Settings.AioDNS.RulePath)));
aiodns_dial((int) NameList.TYPE_CDNS, Encoding.UTF8.GetBytes($"{Global.Settings.AioDNS.ChinaDNS}"));
aiodns_dial((int) NameList.TYPE_ODNS, Encoding.UTF8.GetBytes($"{Global.Settings.AioDNS.OtherDNS}"));
Dial(NameList.TYPE_REST, "");
Dial(NameList.TYPE_ADDR, $"{Global.Settings.LocalAddress}:{Global.Settings.AioDNS.ListenPort}");
Dial(NameList.TYPE_LIST, Path.GetFullPath(Global.Settings.AioDNS.RulePath));
Dial(NameList.TYPE_CDNS, $"{Global.Settings.AioDNS.ChinaDNS}");
Dial(NameList.TYPE_ODNS, $"{Global.Settings.AioDNS.OtherDNS}");
if (!aiodns_init())
if (!Init())
throw new Exception("AioDNS start failed");
}
#region NativeMethods
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
public static extern bool aiodns_dial(int name, byte[]? value);
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
public static extern bool aiodns_init();
[DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)]
public static extern void aiodns_free();
public enum NameList
{
TYPE_REST,
TYPE_ADDR,
TYPE_LIST,
TYPE_CDNS,
TYPE_ODNS
}
#endregion
}
}