Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
AndroidUtils
VPNTunnelProxy
Commits
35793998
Commit
35793998
authored
Jun 06, 2021
by
Daniel Wolf
Browse files
Catch IO errors in IO operations
parent
dd731f54
Changes
1
Hide whitespace changes
Inline
Side-by-side
library/src/main/java/com/frostnerd/vpntunnelproxy/VPNTunnelProxy.kt
View file @
35793998
...
...
@@ -70,6 +70,7 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
private
var
proxyThreadActive
:
Boolean
=
false
private
var
cleanupFinalized
:
Boolean
=
false
private
val
clearLock
=
ReentrantReadWriteLock
()
private
var
ioErrors
=
0
constructor
(
packetProxy
:
PacketProxy
,
trafficStats
:
TrafficStats
=
TrafficStats
(
0
,
0
),
...
...
@@ -175,9 +176,9 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
logger
?.
info
(
"Device filed descriptors became invalid"
)
shouldRun
=
false
}
else
{
if
(
pollableAnswers
.
second
.
isNotEmpty
())
processFutureAnswers
(
pollableAnswers
.
second
,
true
)
if
(
deviceOutputPipe
.
actualEvent
(
OsConstants
.
POLLOUT
))
fromLoopbackToDevice
(
deviceOutput
)
// There is data in loopback
if
(
deviceInputPipe
.
actualEvent
(
OsConstants
.
POLLIN
))
fromDeviceToPacketProxy
(
deviceInput
)
if
(
pollableAnswers
.
second
.
isNotEmpty
())
tryIO
{
processFutureAnswers
(
pollableAnswers
.
second
,
true
)
}
if
(
deviceOutputPipe
.
actualEvent
(
OsConstants
.
POLLOUT
))
tryIO
{
fromLoopbackToDevice
(
deviceOutput
)
}
// There is data in loopback
if
(
deviceInputPipe
.
actualEvent
(
OsConstants
.
POLLIN
))
tryIO
{
fromDeviceToPacketProxy
(
deviceInput
)
}
Thread
.
sleep
(
1
)
}
}
else
if
(
shouldRun
)
{
...
...
@@ -236,6 +237,20 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
logger
?.
info
(
"Done with run()."
)
}
private
fun
tryIO
(
block
:()
->
Unit
)
{
try
{
block
()
}
catch
(
ex
:
IOException
)
{
if
(
ex
is
InterruptedIOException
)
throw
ex
// Continued errors might indicate an underlying problem.
// either way, 100 is a lot and takes a lot of time to reach
// (besides, this error is again caught in another try)
if
(++
ioErrors
>=
100
)
{
throw
ex
}
}
}
private
val
packetFromDevice
=
ByteArray
(
32767
)
fun
fromDeviceToPacketProxy
(
deviceInput
:
InputStream
)
{
val
readSize
=
deviceInput
.
read
(
packetFromDevice
)
...
...
Write
Preview
Supports
Markdown
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