Merge pull request #4712 from hxdhttk/hxdhttk/statePortConf

Fix the state ports conflicts when multiple `v2rayN` instances start in a short period.
pull/4729/head
2dust 2024-02-13 09:57:59 +08:00 committed by GitHub
commit 9b3ac159c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 6 deletions

View File

@ -11,14 +11,24 @@ namespace v2rayN.Handler
public static LazyConfig Instance => _instance.Value;
private int _statePort;
public int StatePort { get => _statePort; }
private Job _processJob = new();
private int? _statePort;
public int StatePort
{
get
{
if (_statePort is null)
{
_statePort = Utils.GetFreePort();
}
return _statePort.Value;
}
}
private Job _processJob = new();
public LazyConfig()
{
_statePort = Utils.GetFreePort();
SqliteHelper.Instance.CreateTable<SubItem>();
SqliteHelper.Instance.CreateTable<ProfileItem>();
SqliteHelper.Instance.CreateTable<ServerStatItem>();
@ -68,7 +78,7 @@ namespace v2rayN.Handler
}
return localPort;
}
public void AddProcess(IntPtr processHandle)
{
_processJob.AddProcess(processHandle);