Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
79d2290d
Commit
79d2290d
authored
Dec 06, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use thread with exception handling in GuardedProcess
parent
39242b69
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
mobile/src/main/java/com/github/shadowsocks/bg/GuardedProcess.kt
...src/main/java/com/github/shadowsocks/bg/GuardedProcess.kt
+7
-7
No files found.
mobile/src/main/java/com/github/shadowsocks/bg/GuardedProcess.kt
View file @
79d2290d
...
@@ -27,13 +27,14 @@ import com.github.shadowsocks.App.Companion.app
...
@@ -27,13 +27,14 @@ import com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.BuildConfig
import
com.github.shadowsocks.BuildConfig
import
com.github.shadowsocks.JniHelper
import
com.github.shadowsocks.JniHelper
import
com.github.shadowsocks.utils.Commandline
import
com.github.shadowsocks.utils.Commandline
import
com.github.shadowsocks.utils.thread
import
java.io.IOException
import
java.io.IOException
import
java.io.InputStream
import
java.io.InputStream
import
java.util.concurrent.Semaphore
import
java.util.concurrent.Semaphore
class
GuardedProcess
(
private
val
cmd
:
List
<
String
>)
{
class
GuardedProcess
(
private
val
cmd
:
List
<
String
>)
{
companion
object
{
companion
object
{
const
val
TAG
=
"GuardedProcess"
private
const
val
TAG
=
"GuardedProcess"
}
}
private
lateinit
var
guardThread
:
Thread
private
lateinit
var
guardThread
:
Thread
...
@@ -42,7 +43,7 @@ class GuardedProcess(private val cmd: List<String>) {
...
@@ -42,7 +43,7 @@ class GuardedProcess(private val cmd: List<String>) {
@Volatile
@Volatile
private
lateinit
var
process
:
Process
private
lateinit
var
process
:
Process
private
fun
streamLogger
(
input
:
InputStream
,
logger
:
(
String
,
String
)
->
Int
)
=
T
hread
{
private
fun
streamLogger
(
input
:
InputStream
,
logger
:
(
String
,
String
)
->
Int
)
=
t
hread
{
try
{
try
{
input
.
bufferedReader
().
useLines
{
it
.
forEach
{
logger
(
TAG
,
it
)
}
}
input
.
bufferedReader
().
useLines
{
it
.
forEach
{
logger
(
TAG
,
it
)
}
}
}
catch
(
_
:
IOException
)
{
}
// ignore
}
catch
(
_
:
IOException
)
{
}
// ignore
...
@@ -52,7 +53,7 @@ class GuardedProcess(private val cmd: List<String>) {
...
@@ -52,7 +53,7 @@ class GuardedProcess(private val cmd: List<String>) {
val
semaphore
=
Semaphore
(
1
)
val
semaphore
=
Semaphore
(
1
)
semaphore
.
acquire
()
semaphore
.
acquire
()
var
ioException
:
IOException
?
=
null
var
ioException
:
IOException
?
=
null
guardThread
=
Thread
(
{
guardThread
=
thread
(
name
=
"GuardThread-"
+
cmd
.
first
())
{
try
{
try
{
var
callback
:
(()
->
Unit
)?
=
null
var
callback
:
(()
->
Unit
)?
=
null
while
(!
isDestroyed
)
{
while
(!
isDestroyed
)
{
...
@@ -64,8 +65,8 @@ class GuardedProcess(private val cmd: List<String>) {
...
@@ -64,8 +65,8 @@ class GuardedProcess(private val cmd: List<String>) {
.
directory
(
app
.
filesDir
)
.
directory
(
app
.
filesDir
)
.
start
()
.
start
()
streamLogger
(
process
.
inputStream
,
Log
::
i
)
.
start
()
streamLogger
(
process
.
inputStream
,
Log
::
i
)
streamLogger
(
process
.
errorStream
,
Log
::
e
)
.
start
()
streamLogger
(
process
.
errorStream
,
Log
::
e
)
if
(
callback
==
null
)
callback
=
onRestartCallback
else
callback
()
if
(
callback
==
null
)
callback
=
onRestartCallback
else
callback
()
...
@@ -87,8 +88,7 @@ class GuardedProcess(private val cmd: List<String>) {
...
@@ -87,8 +88,7 @@ class GuardedProcess(private val cmd: List<String>) {
}
finally
{
}
finally
{
semaphore
.
release
()
semaphore
.
release
()
}
}
},
"GuardThread-"
+
cmd
.
first
())
}
guardThread
.
start
()
semaphore
.
acquire
()
semaphore
.
acquire
()
if
(
ioException
!=
null
)
throw
ioException
!!
if
(
ioException
!=
null
)
throw
ioException
!!
return
this
return
this
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment