Use job objects with SIP003 plugin to avoid lingering processes if app is killed.

This commit is contained in:
Raif Atef
2017-08-23 12:36:32 +02:00
parent 71120e5c3e
commit cf5de91acb
@@ -5,6 +5,7 @@ using System.Net;
using System.Net.Sockets;
using System.Reflection;
using Shadowsocks.Model;
using Shadowsocks.Util.ProcessManagement;
namespace Shadowsocks.Controller.Service
{
@@ -15,6 +16,7 @@ namespace Shadowsocks.Controller.Service
public int ProcessId => _started ? _pluginProcess.Id : 0;
private readonly object _startProcessLock = new object();
private readonly Job _pluginJob;
private readonly Process _pluginProcess;
private bool _started;
private bool _disposed;
@@ -66,6 +68,8 @@ namespace Shadowsocks.Controller.Service
}
}
};
_pluginJob = new Job();
}
public bool StartIfNeeded()
@@ -88,6 +92,7 @@ namespace Shadowsocks.Controller.Service
_pluginProcess.StartInfo.Environment["SS_LOCAL_HOST"] = LocalEndPoint.Address.ToString();
_pluginProcess.StartInfo.Environment["SS_LOCAL_PORT"] = LocalEndPoint.Port.ToString();
_pluginProcess.Start();
_pluginJob.AddProcess(_pluginProcess.Handle);
_started = true;
}
@@ -124,6 +129,7 @@ namespace Shadowsocks.Controller.Service
try
{
_pluginProcess.Dispose();
_pluginJob.Dispose();
}
catch (Exception) { }