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
fe58f13e
Commit
fe58f13e
authored
Jan 24, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent blocking sleep
parent
3cfc17c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
10 deletions
+8
-10
core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt
...main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt
+6
-8
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
+2
-2
No files found.
core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt
View file @
fe58f13e
...
@@ -48,7 +48,6 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
...
@@ -48,7 +48,6 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
private
inner
class
Guard
(
private
val
cmd
:
List
<
String
>)
{
private
inner
class
Guard
(
private
val
cmd
:
List
<
String
>)
{
private
val
abortChannel
=
Channel
<
Unit
>()
private
val
abortChannel
=
Channel
<
Unit
>()
private
var
startTime
:
Long
=
-
1
private
lateinit
var
process
:
Process
private
lateinit
var
process
:
Process
private
fun
streamLogger
(
input
:
InputStream
,
logger
:
(
String
)
->
Unit
)
=
try
{
private
fun
streamLogger
(
input
:
InputStream
,
logger
:
(
String
)
->
Unit
)
=
try
{
...
@@ -56,7 +55,6 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
...
@@ -56,7 +55,6 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
}
catch
(
_
:
IOException
)
{
}
// ignore
}
catch
(
_
:
IOException
)
{
}
// ignore
fun
start
()
{
fun
start
()
{
startTime
=
SystemClock
.
elapsedRealtime
()
process
=
ProcessBuilder
(
cmd
).
directory
(
Core
.
deviceStorage
.
noBackupFilesDir
).
start
()
process
=
ProcessBuilder
(
cmd
).
directory
(
Core
.
deviceStorage
.
noBackupFilesDir
).
start
()
}
}
...
@@ -64,7 +62,7 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
...
@@ -64,7 +62,7 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
if
(!
abortChannel
.
isClosedForSend
)
abortChannel
.
send
(
Unit
)
if
(!
abortChannel
.
isClosedForSend
)
abortChannel
.
send
(
Unit
)
}
}
suspend
fun
looper
(
onRestartCallback
:
(()
->
Unit
)?)
{
suspend
fun
looper
(
onRestartCallback
:
(
suspend
()
->
Unit
)?)
{
var
running
=
true
var
running
=
true
val
cmdName
=
File
(
cmd
.
first
()).
nameWithoutExtension
val
cmdName
=
File
(
cmd
.
first
()).
nameWithoutExtension
val
exitChannel
=
Channel
<
Int
>()
val
exitChannel
=
Channel
<
Int
>()
...
@@ -72,11 +70,11 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
...
@@ -72,11 +70,11 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
while
(
true
)
{
while
(
true
)
{
thread
(
name
=
"stderr-$cmdName"
)
{
streamLogger
(
process
.
errorStream
)
{
Log
.
e
(
cmdName
,
it
)
}
}
thread
(
name
=
"stderr-$cmdName"
)
{
streamLogger
(
process
.
errorStream
)
{
Log
.
e
(
cmdName
,
it
)
}
}
thread
(
name
=
"stdout-$cmdName"
)
{
thread
(
name
=
"stdout-$cmdName"
)
{
runBlocking
{
streamLogger
(
process
.
inputStream
)
{
Log
.
i
(
cmdName
,
it
)
}
streamLogger
(
process
.
inputStream
)
{
Log
.
i
(
cmdName
,
it
)
}
// this thread also acts as a daemon thread for waitFor
exitChannel
.
send
(
process
.
waitFor
())
// this thread also acts as a daemon thread for waitFor
runBlocking
{
exitChannel
.
send
(
process
.
waitFor
())
}
}
}
}
val
startTime
=
SystemClock
.
elapsedRealtime
()
if
(
select
{
if
(
select
{
abortChannel
.
onReceive
{
true
}
// prefer abort to save work
abortChannel
.
onReceive
{
true
}
// prefer abort to save work
exitChannel
.
onReceive
{
false
}
exitChannel
.
onReceive
{
false
}
...
@@ -118,7 +116,7 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
...
@@ -118,7 +116,7 @@ class GuardedProcessPool(private val onFatal: (IOException) -> Unit) : Coroutine
private
val
guards
=
ArrayList
<
Guard
>()
private
val
guards
=
ArrayList
<
Guard
>()
@MainThread
@MainThread
suspend
fun
start
(
cmd
:
List
<
String
>,
onRestartCallback
:
(()
->
Unit
)?
=
null
)
{
suspend
fun
start
(
cmd
:
List
<
String
>,
onRestartCallback
:
(
suspend
()
->
Unit
)?
=
null
)
{
Crashlytics
.
log
(
Log
.
DEBUG
,
TAG
,
"start process: "
+
Commandline
.
toString
(
cmd
))
Crashlytics
.
log
(
Log
.
DEBUG
,
TAG
,
"start process: "
+
Commandline
.
toString
(
cmd
))
val
guard
=
Guard
(
cmd
)
val
guard
=
Guard
(
cmd
)
guard
.
start
()
guard
.
start
()
...
...
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
View file @
fe58f13e
...
@@ -267,11 +267,11 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
...
@@ -267,11 +267,11 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
return
conn
.
fileDescriptor
return
conn
.
fileDescriptor
}
}
private
fun
sendFd
(
fd
:
FileDescriptor
)
{
private
suspend
fun
sendFd
(
fd
:
FileDescriptor
)
{
var
tries
=
0
var
tries
=
0
val
path
=
File
(
Core
.
deviceStorage
.
noBackupFilesDir
,
"sock_path"
).
absolutePath
val
path
=
File
(
Core
.
deviceStorage
.
noBackupFilesDir
,
"sock_path"
).
absolutePath
while
(
true
)
try
{
while
(
true
)
try
{
Thread
.
sleep
(
50L
shl
tries
)
delay
(
50L
shl
tries
)
LocalSocket
().
use
{
localSocket
->
LocalSocket
().
use
{
localSocket
->
localSocket
.
connect
(
LocalSocketAddress
(
path
,
LocalSocketAddress
.
Namespace
.
FILESYSTEM
))
localSocket
.
connect
(
LocalSocketAddress
(
path
,
LocalSocketAddress
.
Namespace
.
FILESYSTEM
))
localSocket
.
setFileDescriptorsForSend
(
arrayOf
(
fd
))
localSocket
.
setFileDescriptorsForSend
(
arrayOf
(
fd
))
...
...
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