Skip to content

Commit

Permalink
Improve XRay protocol process close
Browse files Browse the repository at this point in the history
  • Loading branch information
outspace committed Dec 26, 2024
1 parent b88ab8e commit 7828594
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions client/protocols/xrayprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ XrayProtocol::XrayProtocol(const QJsonObject &configuration, QObject *parent):

XrayProtocol::~XrayProtocol()
{
qDebug() << "XrayProtocol::~XrayProtocol()";
XrayProtocol::stop();
QThread::msleep(200);
m_xrayProcess.close();
}

ErrorCode XrayProtocol::start()
Expand Down Expand Up @@ -68,13 +67,9 @@ ErrorCode XrayProtocol::start()
connect(&m_xrayProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug().noquote() << "XrayProtocol finished, exitCode, exitStatus" << exitCode << exitStatus;
setConnectionState(Vpn::ConnectionState::Disconnected);
if (exitStatus != QProcess::NormalExit) {
emit protocolError(amnezia::ErrorCode::XrayExecutableCrashed);
stop();
}
if (exitCode != 0) {
emit protocolError(amnezia::ErrorCode::InternalError);
stop();
if ((exitStatus != QProcess::NormalExit) || (exitCode != 0)) {
emit protocolError(amnezia::ErrorCode::XrayExecutableCrashed);
emit setConnectionState(Vpn::ConnectionState::Error);
}
});

Expand Down Expand Up @@ -176,8 +171,13 @@ void XrayProtocol::stop()
IpcClient::Interface()->disableKillSwitch();
IpcClient::Interface()->StartRoutingIpv6();
#endif

qDebug() << "XrayProtocol::stop()";
m_xrayProcess.terminate();

disconnect(&m_xrayProcess);
m_xrayProcess.kill();
m_xrayProcess.waitForFinished(3000);

if (m_t2sProcess) {
m_t2sProcess->stop();
}
Expand Down
14 changes: 7 additions & 7 deletions ipc/ipctun2socksprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ IpcProcessTun2Socks::IpcProcessTun2Socks(QObject *parent) :
IpcProcessTun2SocksSource(parent),
m_t2sProcess(QSharedPointer<QProcess>(new QProcess()))
{
connect(m_t2sProcess.data(), &QProcess::stateChanged, this, &IpcProcessTun2Socks::stateChanged);
qDebug() << "IpcProcessTun2Socks::IpcProcessTun2Socks()";

}
Expand All @@ -23,6 +22,7 @@ IpcProcessTun2Socks::~IpcProcessTun2Socks()

void IpcProcessTun2Socks::start()
{
connect(m_t2sProcess.data(), &QProcess::stateChanged, this, &IpcProcessTun2Socks::stateChanged);
qDebug() << "IpcProcessTun2Socks::start()";
m_t2sProcess->setProgram(amnezia::permittedProcessPath(static_cast<amnezia::PermittedProcess>(amnezia::PermittedProcess::Tun2Socks)));
QString XrayConStr = "socks5://127.0.0.1:10808";
Expand Down Expand Up @@ -54,12 +54,10 @@ void IpcProcessTun2Socks::start()
connect(m_t2sProcess.data(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug().noquote() << "tun2socks finished, exitCode, exiStatus" << exitCode << exitStatus;
emit setConnectionState(Vpn::ConnectionState::Disconnected);
if (exitStatus != QProcess::NormalExit){
stop();
}
if (exitCode !=0 ){
stop();
if ((exitStatus != QProcess::NormalExit) || (exitCode != 0)) {
emit setConnectionState(Vpn::ConnectionState::Error);
}

});

m_t2sProcess->start();
Expand All @@ -69,6 +67,8 @@ void IpcProcessTun2Socks::start()
void IpcProcessTun2Socks::stop()
{
qDebug() << "IpcProcessTun2Socks::stop()";
m_t2sProcess->close();
disconnect(m_t2sProcess.data());
m_t2sProcess->kill();
m_t2sProcess->waitForFinished(3000);
}
#endif

0 comments on commit 7828594

Please sign in to comment.