pull/188/head 2.47
2dust 2019-10-23 15:18:21 +08:00
parent c0340843eb
commit ef01b4aa5e
7 changed files with 48 additions and 39 deletions

View File

@ -39,8 +39,14 @@ namespace v2rayN.Base
while (true) while (true)
{ {
if (!listener.Pending())
{
continue;
}
TcpClient socket = listener.AcceptTcpClient(); TcpClient socket = listener.AcceptTcpClient();
Thread thread = new Thread(new ParameterizedThreadStart(ProcessThread)); Thread thread = new Thread(new ParameterizedThreadStart(ProcessThread));
thread.IsBackground = true;
thread.Start(socket); thread.Start(socket);
Thread.Sleep(1); Thread.Sleep(1);
} }

View File

@ -33,6 +33,13 @@ namespace v2rayN.Forms
Application.ApplicationExit += (sender, args) => Application.ApplicationExit += (sender, args) =>
{ {
Utils.ClearTempPath(); Utils.ClearTempPath();
v2rayHandler.V2rayStop();
HttpProxyHandle.CloseHttpAgent(config);
PACServerHandle.Stop();
ConfigHandler.SaveConfig(ref config);
statistics?.SaveToFile();
statistics?.Close(); statistics?.Close();
}; };
} }
@ -79,18 +86,9 @@ namespace v2rayN.Forms
if (e.CloseReason == CloseReason.UserClosing) if (e.CloseReason == CloseReason.UserClosing)
{ {
e.Cancel = true; e.Cancel = true;
statistics?.SaveToFile();
HideForm(); HideForm();
return; return;
} }
if (e.CloseReason == CloseReason.ApplicationExitCall)
{
ConfigHandler.SaveConfig(ref config);
statistics?.SaveToFile();
statistics?.Close();
}
} }
private void MainForm_Resize(object sender, EventArgs e) private void MainForm_Resize(object sender, EventArgs e)
@ -117,7 +115,7 @@ namespace v2rayN.Forms
{ {
case WM_QUERYENDSESSION: case WM_QUERYENDSESSION:
Utils.SaveLog("Windows shutdown UnsetProxy"); Utils.SaveLog("Windows shutdown UnsetProxy");
//CloseV2ray();
ConfigHandler.ToJsonFile(config); ConfigHandler.ToJsonFile(config);
statistics?.SaveToFile(); statistics?.SaveToFile();
ProxySetting.UnsetProxy(); ProxySetting.UnsetProxy();
@ -1006,16 +1004,11 @@ namespace v2rayN.Forms
} }
private void menuExit_Click(object sender, EventArgs e) private void menuExit_Click(object sender, EventArgs e)
{ {
CloseV2ray();
this.Visible = false; this.Visible = false;
this.Close(); this.Close();
statistics?.Close();
//this.Dispose();
//System.Environment.Exit(System.Environment.ExitCode);
Application.Exit(); Application.Exit();
} }

View File

@ -37,16 +37,19 @@ namespace v2rayN.Handler
if (actionType == "ping") if (actionType == "ping")
{ {
_workThread = new Thread(new ThreadStart(RunPing)); _workThread = new Thread(new ThreadStart(RunPing));
_workThread.IsBackground = true;
_workThread.Start(); _workThread.Start();
} }
if (actionType == "tcping") if (actionType == "tcping")
{ {
_workThread = new Thread(new ThreadStart(RunTcping)); _workThread = new Thread(new ThreadStart(RunTcping));
_workThread.IsBackground = true;
_workThread.Start(); _workThread.Start();
} }
else if (actionType == "realping") else if (actionType == "realping")
{ {
_workThread = new Thread(new ThreadStart(RunRealPing)); _workThread = new Thread(new ThreadStart(RunRealPing));
_workThread.IsBackground = true;
_workThread.Start(); _workThread.Start();
} }
else if (actionType == "speedtest") else if (actionType == "speedtest")

View File

@ -105,6 +105,7 @@ namespace v2rayN.Handler
GrpcInit(); GrpcInit();
workThread_ = new Thread(new ThreadStart(Run)); workThread_ = new Thread(new ThreadStart(Run));
workThread_.IsBackground = true;
workThread_.Start(); workThread_.Start();
} }

View File

@ -30,33 +30,33 @@ namespace v2rayN.HttpProxyHandler
} }
if (type == 1) if (type == 1)
{ {
PACServerHandle.Stop(); //PACServerHandle.Stop();
SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}", null); SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}", null);
} }
else if (type == 2) else if (type == 2)
{ {
string pacUrl = GetPacUrl(); string pacUrl = GetPacUrl();
SysProxyHandle.SetIEProxy(true, false, null, pacUrl); SysProxyHandle.SetIEProxy(true, false, null, pacUrl);
PACServerHandle.Stop(); //PACServerHandle.Stop();
PACServerHandle.Init(config); PACServerHandle.Init(config);
} }
else if (type == 3) else if (type == 3)
{ {
PACServerHandle.Stop(); //PACServerHandle.Stop();
SysProxyHandle.SetIEProxy(false, false, null, null); SysProxyHandle.SetIEProxy(false, false, null, null);
} }
else if (type == 4) else if (type == 4)
{ {
string pacUrl = GetPacUrl(); string pacUrl = GetPacUrl();
SysProxyHandle.SetIEProxy(false, false, null, null); SysProxyHandle.SetIEProxy(false, false, null, null);
PACServerHandle.Stop(); //PACServerHandle.Stop();
PACServerHandle.Init(config); PACServerHandle.Init(config);
} }
} }
else else
{ {
SysProxyHandle.SetIEProxy(false, false, null, null); SysProxyHandle.SetIEProxy(false, false, null, null);
PACServerHandle.Stop(); //PACServerHandle.Stop();
} }
} }
catch (Exception ex) catch (Exception ex)
@ -104,8 +104,7 @@ namespace v2rayN.HttpProxyHandler
Global.sysAgent = false; Global.sysAgent = false;
Global.socksPort = 0; Global.socksPort = 0;
Global.httpPort = 0; Global.httpPort = 0;
Global.pacPort = 0;
} }
catch catch
{ {

View File

@ -28,6 +28,8 @@ namespace v2rayN.HttpProxyHandler
public static void Init(Config config) public static void Init(Config config)
{ {
Global.pacPort = config.GetLocalPort("pac");
if (InitServer("*")) if (InitServer("*"))
{ {
pacPort = Global.pacPort; pacPort = Global.pacPort;
@ -122,18 +124,23 @@ namespace v2rayN.HttpProxyHandler
public static void Stop() public static void Stop()
{ {
//try try
//{ {
// if (server != null) if (server != null)
// { {
// server.Stop(); server.Stop();
// server = null; server = null;
// } }
//} if (serverB != null)
//catch (Exception ex) {
//{ serverB.Stop();
// Utils.SaveLog("Webserver Stop " + ex.Message); serverB = null;
//} }
}
catch (Exception ex)
{
Utils.SaveLog("Webserver Stop " + ex.Message);
}
//try //try
//{ //{

View File

@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
// 方法是按如下所示使用“*”: // 方法是按如下所示使用“*”:
//[assembly: AssemblyVersion("1.0.*")] //[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0")] //[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("2.46")] [assembly: AssemblyFileVersion("2.47")]