Restart kcptun when switching network
This commit is contained in:
@@ -56,6 +56,7 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
|
||||
@volatile private var guardThread: Thread = _
|
||||
@volatile private var isDestroyed: Boolean = _
|
||||
@volatile private var process: Process = _
|
||||
@volatile private var isRestart = false
|
||||
|
||||
def start(onRestartCallback: () => Unit = null): GuardedProcess = {
|
||||
val semaphore = new Semaphore(1)
|
||||
@@ -76,9 +77,13 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
|
||||
semaphore.release
|
||||
process.waitFor
|
||||
|
||||
if (currentTimeMillis - startTime < 1000) {
|
||||
Log.w(TAG, "process exit too fast, stop guard: " + cmd)
|
||||
isDestroyed = true
|
||||
if (isRestart) {
|
||||
isRestart = false
|
||||
} else {
|
||||
if (currentTimeMillis - startTime < 1000) {
|
||||
Log.w(TAG, "process exit too fast, stop guard: " + cmd)
|
||||
isDestroyed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
@@ -108,6 +113,11 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
|
||||
}
|
||||
}
|
||||
|
||||
def restart() {
|
||||
isRestart = true
|
||||
process.destroy()
|
||||
}
|
||||
|
||||
def exitValue: Int = throw new UnsupportedOperationException
|
||||
def getErrorStream: InputStream = throw new UnsupportedOperationException
|
||||
def getInputStream: InputStream = throw new UnsupportedOperationException
|
||||
|
||||
Reference in New Issue
Block a user