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
33d866ae
Commit
33d866ae
authored
Feb 03, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ignore IOException for selector.select
parent
02e10607
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
...rc/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
+12
-6
No files found.
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
View file @
33d866ae
...
@@ -20,12 +20,11 @@
...
@@ -20,12 +20,11 @@
package
com.github.shadowsocks.net
package
com.github.shadowsocks.net
import
com.github.shadowsocks.utils.printLog
import
kotlinx.coroutines.suspendCancellableCoroutine
import
kotlinx.coroutines.suspendCancellableCoroutine
import
java.io.IOException
import
java.nio.ByteBuffer
import
java.nio.ByteBuffer
import
java.nio.channels.Pipe
import
java.nio.channels.*
import
java.nio.channels.SelectableChannel
import
java.nio.channels.SelectionKey
import
java.nio.channels.Selector
import
java.util.concurrent.ConcurrentLinkedQueue
import
java.util.concurrent.ConcurrentLinkedQueue
import
kotlin.coroutines.resume
import
kotlin.coroutines.resume
...
@@ -57,7 +56,7 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
...
@@ -57,7 +56,7 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
fun
register
(
channel
:
SelectableChannel
,
ops
:
Int
,
block
:
(
SelectionKey
)
->
Unit
)
{
fun
register
(
channel
:
SelectableChannel
,
ops
:
Int
,
block
:
(
SelectionKey
)
->
Unit
)
{
pendingRegistrations
.
add
(
Triple
(
channel
,
ops
,
block
))
pendingRegistrations
.
add
(
Triple
(
channel
,
ops
,
block
))
val
junk
=
ByteBuffer
.
allocateDirect
(
1
)
val
junk
=
ByteBuffer
.
allocateDirect
(
1
)
while
(
registrationPipe
.
sink
().
write
(
junk
)
==
0
);
while
(
r
unning
&&
r
egistrationPipe
.
sink
().
write
(
junk
)
==
0
);
}
}
suspend
fun
wait
(
channel
:
SelectableChannel
,
ops
:
Int
)
=
suspendCancellableCoroutine
<
Unit
>
{
cont
->
suspend
fun
wait
(
channel
:
SelectableChannel
,
ops
:
Int
)
=
suspendCancellableCoroutine
<
Unit
>
{
cont
->
...
@@ -69,7 +68,13 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
...
@@ -69,7 +68,13 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
override
fun
run
()
{
override
fun
run
()
{
while
(
running
)
{
while
(
running
)
{
if
(
selector
.
select
()
<=
0
)
continue
val
num
=
try
{
selector
.
select
()
}
catch
(
e
:
IOException
)
{
printLog
(
e
)
continue
}
if
(
num
<=
0
)
continue
val
iterator
=
selector
.
selectedKeys
().
iterator
()
val
iterator
=
selector
.
selectedKeys
().
iterator
()
while
(
iterator
.
hasNext
())
{
while
(
iterator
.
hasNext
())
{
val
key
=
iterator
.
next
()
val
key
=
iterator
.
next
()
...
@@ -84,5 +89,6 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
...
@@ -84,5 +89,6 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
selector
.
wakeup
()
selector
.
wakeup
()
join
()
join
()
selector
.
keys
().
forEach
{
it
.
channel
().
close
()
}
selector
.
keys
().
forEach
{
it
.
channel
().
close
()
}
selector
.
close
()
}
}
}
}
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