Skip to content

Commit

Permalink
fix pac
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 23, 2019
1 parent c034084 commit ef01b4a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 39 deletions.
6 changes: 6 additions & 0 deletions v2rayN/v2rayN/Base/HttpWebServerB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ private void StartListen()

while (true)
{
if (!listener.Pending())
{
continue;
}

TcpClient socket = listener.AcceptTcpClient();
Thread thread = new Thread(new ParameterizedThreadStart(ProcessThread));
thread.IsBackground = true;
thread.Start(socket);
Thread.Sleep(1);
}
Expand Down
31 changes: 12 additions & 19 deletions v2rayN/v2rayN/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public MainForm()
Application.ApplicationExit += (sender, args) =>
{
Utils.ClearTempPath();

v2rayHandler.V2rayStop();
HttpProxyHandle.CloseHttpAgent(config);
PACServerHandle.Stop();

ConfigHandler.SaveConfig(ref config);
statistics?.SaveToFile();
statistics?.Close();
};
}
Expand Down Expand Up @@ -79,18 +86,9 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;

statistics?.SaveToFile();

HideForm();
return;
}
if (e.CloseReason == CloseReason.ApplicationExitCall)
{
ConfigHandler.SaveConfig(ref config);
statistics?.SaveToFile();
statistics?.Close();
}
}
}

private void MainForm_Resize(object sender, EventArgs e)
Expand All @@ -117,7 +115,7 @@ protected override void WndProc(ref Message m)
{
case WM_QUERYENDSESSION:
Utils.SaveLog("Windows shutdown UnsetProxy");
//CloseV2ray();

ConfigHandler.ToJsonFile(config);
statistics?.SaveToFile();
ProxySetting.UnsetProxy();
Expand Down Expand Up @@ -1006,16 +1004,11 @@ private void notifyMain_MouseClick(object sender, MouseEventArgs e)
}

private void menuExit_Click(object sender, EventArgs e)
{
CloseV2ray();
{

this.Visible = false;
this.Close();

statistics?.Close();

//this.Dispose();
//System.Environment.Exit(System.Environment.ExitCode);
this.Close();

Application.Exit();
}

Expand Down
3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Handler/SpeedtestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ public SpeedtestHandler(ref Config config, ref V2rayHandler v2rayHandler, List<i
if (actionType == "ping")
{
_workThread = new Thread(new ThreadStart(RunPing));
_workThread.IsBackground = true;
_workThread.Start();
}
if (actionType == "tcping")
{
_workThread = new Thread(new ThreadStart(RunTcping));
_workThread.IsBackground = true;
_workThread.Start();
}
else if (actionType == "realping")
{
_workThread = new Thread(new ThreadStart(RunRealPing));
_workThread.IsBackground = true;
_workThread.Start();
}
else if (actionType == "speedtest")
Expand Down
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Handler/StatisticsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public StatisticsHandler(Mode.Config config, Action<ulong, ulong, ulong, ulong,
GrpcInit();

workThread_ = new Thread(new ThreadStart(Run));
workThread_.IsBackground = true;
workThread_.Start();
}

Expand Down
13 changes: 6 additions & 7 deletions v2rayN/v2rayN/HttpProxyHandler/HttpProxyHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@ public static bool Update(Config config, bool forceDisable)
}
if (type == 1)
{
PACServerHandle.Stop();
//PACServerHandle.Stop();
SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}", null);
}
else if (type == 2)
{
string pacUrl = GetPacUrl();
SysProxyHandle.SetIEProxy(true, false, null, pacUrl);
PACServerHandle.Stop();
//PACServerHandle.Stop();
PACServerHandle.Init(config);
}
else if (type == 3)
{
PACServerHandle.Stop();
//PACServerHandle.Stop();
SysProxyHandle.SetIEProxy(false, false, null, null);
}
else if (type == 4)
{
string pacUrl = GetPacUrl();
SysProxyHandle.SetIEProxy(false, false, null, null);
PACServerHandle.Stop();
//PACServerHandle.Stop();
PACServerHandle.Init(config);
}
}
else
{
SysProxyHandle.SetIEProxy(false, false, null, null);
PACServerHandle.Stop();
//PACServerHandle.Stop();
}
}
catch (Exception ex)
Expand Down Expand Up @@ -104,8 +104,7 @@ public static void CloseHttpAgent(Config config)

Global.sysAgent = false;
Global.socksPort = 0;
Global.httpPort = 0;
Global.pacPort = 0;
Global.httpPort = 0;
}
catch
{
Expand Down
31 changes: 19 additions & 12 deletions v2rayN/v2rayN/HttpProxyHandler/PACServerHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static bool IsRunning

public static void Init(Config config)
{
Global.pacPort = config.GetLocalPort("pac");

if (InitServer("*"))
{
pacPort = Global.pacPort;
Expand Down Expand Up @@ -122,18 +124,23 @@ public static string SendResponse(string address)

public static void Stop()
{
//try
//{
// if (server != null)
// {
// server.Stop();
// server = null;
// }
//}
//catch (Exception ex)
//{
// Utils.SaveLog("Webserver Stop " + ex.Message);
//}
try
{
if (server != null)
{
server.Stop();
server = null;
}
if (serverB != null)
{
serverB.Stop();
serverB = null;
}
}
catch (Exception ex)
{
Utils.SaveLog("Webserver Stop " + ex.Message);
}

//try
//{
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// 方法是按如下所示使用“*”:
//[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("2.46")]
[assembly: AssemblyFileVersion("2.47")]

0 comments on commit ef01b4a

Please sign in to comment.