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
667a9f95
Commit
667a9f95
authored
Jul 18, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #2222 on non-Android-go variants
parent
e6d3c557
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt
.../main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt
+18
-6
No files found.
core/src/main/java/com/github/shadowsocks/bg/DnsResolverCompat.kt
View file @
667a9f95
...
...
@@ -21,18 +21,20 @@
package
com.github.shadowsocks.bg
import
android.annotation.TargetApi
import
android.app.ActivityManager
import
android.net.DnsResolver
import
android.net.Network
import
android.os.Build
import
android.os.CancellationSignal
import
androidx.core.content.getSystemService
import
com.github.shadowsocks.Core
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.async
import
kotlinx.coroutines.suspendCancellableCoroutine
import
com.github.shadowsocks.Core.app
import
kotlinx.coroutines.*
import
java.io.IOException
import
java.lang.Runnable
import
java.net.InetAddress
import
java.util.concurrent.Executor
import
java.util.concurrent.Executors
import
kotlin.coroutines.resume
import
kotlin.coroutines.resumeWithException
...
...
@@ -48,10 +50,20 @@ sealed class DnsResolverCompat {
abstract
suspend
fun
resolveOnActiveNetwork
(
host
:
String
):
Array
<
InetAddress
>
private
object
DnsResolverCompat21
:
DnsResolverCompat
()
{
/**
* This dispatcher is used for noncancellable possibly-forever-blocking operations in network IO.
*
* See also: https://issuetracker.google.com/issues/133874590
*/
private
val
unboundedIO
by
lazy
{
if
(
app
.
getSystemService
<
ActivityManager
>()
!!
.
isLowRamDevice
)
Dispatchers
.
IO
else
Executors
.
newCachedThreadPool
().
asCoroutineDispatcher
()
}
override
suspend
fun
resolve
(
network
:
Network
,
host
:
String
)
=
GlobalScope
.
async
(
Dispatchers
.
IO
)
{
network
.
getAllByName
(
host
)
}.
await
()
GlobalScope
.
async
(
unbounded
IO
)
{
network
.
getAllByName
(
host
)
}.
await
()
override
suspend
fun
resolveOnActiveNetwork
(
host
:
String
)
=
GlobalScope
.
async
(
Dispatchers
.
IO
)
{
InetAddress
.
getAllByName
(
host
)
}.
await
()
GlobalScope
.
async
(
unbounded
IO
)
{
InetAddress
.
getAllByName
(
host
)
}.
await
()
}
@TargetApi
(
29
)
...
...
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