mirror of
https://github.com/snltty/linker.git
synced 2025-10-05 09:06:54 +08:00
175
This commit is contained in:
@@ -9,6 +9,7 @@ using AndroidX.Core.App;
|
|||||||
using AndroidX.Core.Content;
|
using AndroidX.Core.Content;
|
||||||
using AndroidX.Core.View;
|
using AndroidX.Core.View;
|
||||||
using Java.IO;
|
using Java.IO;
|
||||||
|
using Java.Nio.Channels;
|
||||||
using linker.app.Services;
|
using linker.app.Services;
|
||||||
using linker.libs;
|
using linker.libs;
|
||||||
using linker.libs.extends;
|
using linker.libs.extends;
|
||||||
@@ -352,8 +353,8 @@ namespace linker.app
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[8 * 1024];
|
byte[] buffer = new byte[65 * 1024];
|
||||||
byte[] bufferWrite = new byte[8 * 1024];
|
byte[] bufferWrite = new byte[65 * 1024];
|
||||||
public byte[] Read(out int length)
|
public byte[] Read(out int length)
|
||||||
{
|
{
|
||||||
length = 0;
|
length = 0;
|
||||||
@@ -366,28 +367,36 @@ namespace linker.app
|
|||||||
{
|
{
|
||||||
length.ToBytes(buffer);
|
length.ToBytes(buffer);
|
||||||
length += 4;
|
length += 4;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
WaitForTunRead();
|
WaitForTun();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
System.Console.WriteLine($"vpn read {ex.ToString()}");
|
||||||
}
|
}
|
||||||
return Helper.EmptyArray;
|
return Helper.EmptyArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly object writeLockObj = new object();
|
||||||
public bool Write(ReadOnlyMemory<byte> buffer)
|
public bool Write(ReadOnlyMemory<byte> buffer)
|
||||||
{
|
{
|
||||||
if (fd == 0) return false;
|
if (fd == 0) return false;
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
lock (writeLockObj)
|
||||||
{
|
{
|
||||||
buffer.CopyTo(bufferWrite);
|
buffer.CopyTo(bufferWrite);
|
||||||
vpnOutput.Write(bufferWrite, 0, buffer.Length);
|
vpnOutput.Write(bufferWrite, 0, buffer.Length);
|
||||||
vpnOutput.Flush();
|
vpnOutput.Flush();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
System.Console.WriteLine($"vpn write {ex.ToString()}");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -445,40 +454,19 @@ namespace linker.app
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void WaitForTunRead()
|
private void WaitForTun()
|
||||||
{
|
|
||||||
WaitForTun(PollEvent.In);
|
|
||||||
}
|
|
||||||
private void WaitForTunWrite()
|
|
||||||
{
|
|
||||||
WaitForTun(PollEvent.Out);
|
|
||||||
}
|
|
||||||
private void WaitForTun(PollEvent pollEvent)
|
|
||||||
{
|
{
|
||||||
var pollFd = new PollFD
|
var pollFd = new PollFD
|
||||||
{
|
{
|
||||||
fd = fd,
|
fd = fd,
|
||||||
events = (short)pollEvent
|
events = 0x001,
|
||||||
|
revents = 0
|
||||||
};
|
};
|
||||||
|
LinuxAPI.poll([pollFd], 1, 500);
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
var result = LinuxAPI.poll([pollFd], 1, -1);
|
|
||||||
if (result >= 0)
|
|
||||||
break;
|
|
||||||
var errorCode = Marshal.GetLastWin32Error();
|
|
||||||
if (errorCode == LinuxAPI.EINTR)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
throw new Exception("fail");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LinuxAPI
|
public static class LinuxAPI
|
||||||
{
|
{
|
||||||
public const int EINTR = 4;
|
|
||||||
public const int EAGAIN = 11;
|
|
||||||
|
|
||||||
[DllImport("libc", SetLastError = true)]
|
[DllImport("libc", SetLastError = true)]
|
||||||
public static extern int poll([In, Out] PollFD[] fds, int nfds, int timeout);
|
public static extern int poll([In, Out] PollFD[] fds, int nfds, int timeout);
|
||||||
}
|
}
|
||||||
@@ -489,11 +477,6 @@ namespace linker.app
|
|||||||
public short events;
|
public short events;
|
||||||
public short revents;
|
public short revents;
|
||||||
}
|
}
|
||||||
public enum PollEvent : short
|
|
||||||
{
|
|
||||||
In = 0x001,
|
|
||||||
Out = 0x004
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -519,7 +502,7 @@ namespace linker.app
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取系统信息
|
/// 获取系统信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SystemInformation: ISystemInformation
|
public sealed class SystemInformation : ISystemInformation
|
||||||
{
|
{
|
||||||
public string Get()
|
public string Get()
|
||||||
{
|
{
|
||||||
@@ -529,4 +512,3 @@ namespace linker.app
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@@ -3,8 +3,8 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
|
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
|
||||||
<ActiveDebugFramework>net8.0-android</ActiveDebugFramework>
|
<ActiveDebugFramework>net8.0-android</ActiveDebugFramework>
|
||||||
<ActiveDebugProfile>Pixel 5 - API 34 (Android 14.0 - API 34)</ActiveDebugProfile>
|
<ActiveDebugProfile>OPPO PFDM00 (Android 12.0 - API 31)</ActiveDebugProfile>
|
||||||
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
|
<SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
|
||||||
<DefaultDevice>pixel_5_-_api_34</DefaultDevice>
|
<DefaultDevice>pixel_5_-_api_34</DefaultDevice>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
v1.7.5
|
v1.7.5
|
||||||
2025-04-26 00:27:31
|
2025-04-26 11:39:08
|
||||||
1. 一些优化
|
1. 一些优化
|
||||||
2. 安卓APP勉强能用
|
2. 安卓APP勉强能用
|
||||||
3. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它
|
3. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它
|
Reference in New Issue
Block a user