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
7ef7644e
Commit
7ef7644e
authored
Feb 03, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine handling timeouts
parent
33d866ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
9 deletions
+8
-9
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
...rc/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
+5
-2
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
...rc/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
+3
-7
No files found.
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
View file @
7ef7644e
...
...
@@ -23,6 +23,7 @@ package com.github.shadowsocks.net
import
com.github.shadowsocks.utils.printLog
import
kotlinx.coroutines.suspendCancellableCoroutine
import
java.io.IOException
import
java.lang.IllegalStateException
import
java.nio.ByteBuffer
import
java.nio.channels.*
import
java.util.concurrent.ConcurrentLinkedQueue
...
...
@@ -61,8 +62,10 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
suspend
fun
wait
(
channel
:
SelectableChannel
,
ops
:
Int
)
=
suspendCancellableCoroutine
<
Unit
>
{
cont
->
register
(
channel
,
ops
)
{
if
(
it
.
isValid
)
it
.
interestOps
(
0
)
// stop listening
cont
.
resume
(
Unit
)
if
(
it
.
isValid
)
it
.
interestOps
(
0
)
// stop listening
try
{
cont
.
resume
(
Unit
)
}
catch
(
_
:
IllegalStateException
)
{
}
// already resumed by a timeout, maybe should use tryResume?
}
}
...
...
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
View file @
7ef7644e
...
...
@@ -65,7 +65,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
private
val
monitor
=
ChannelMonitor
()
private
val
job
=
SupervisorJob
()
override
val
coroutineContext
=
Dispatchers
.
Default
+
job
override
val
coroutineContext
=
Dispatchers
.
Default
+
job
+
CoroutineExceptionHandler
{
_
,
t
->
printLog
(
t
)
}
fun
start
(
listen
:
SocketAddress
)
=
DatagramChannel
.
open
().
apply
{
configureBlocking
(
false
)
...
...
@@ -75,12 +75,8 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val
source
=
receive
(
buffer
)
!!
buffer
.
flip
()
launch
{
try
{
val
reply
=
resolve
(
buffer
)
while
(
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
this
@apply
,
SelectionKey
.
OP_WRITE
)
}
catch
(
e
:
Exception
)
{
printLog
(
e
)
}
val
reply
=
resolve
(
buffer
)
while
(
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
this
@apply
,
SelectionKey
.
OP_WRITE
)
}
}
}
...
...
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