Commit 44c5180d authored by Mygod's avatar Mygod

Refine EOF exception

parent 5905625f
...@@ -25,6 +25,7 @@ import com.crashlytics.android.Crashlytics ...@@ -25,6 +25,7 @@ import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.utils.printLog import com.github.shadowsocks.utils.printLog
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.xbill.DNS.* import org.xbill.DNS.*
import java.io.EOFException
import java.io.IOException import java.io.IOException
import java.net.* import java.net.*
import java.nio.ByteBuffer import java.nio.ByteBuffer
...@@ -131,6 +132,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd ...@@ -131,6 +132,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
when (e) { when (e) {
is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out") is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out")
is CancellationException -> { } // ignore is CancellationException -> { } // ignore
is EOFException -> Crashlytics.log(Log.WARN, TAG, e.message)
else -> printLog(e) else -> printLog(e)
} }
ByteBuffer.wrap(prepareDnsResponse(request).apply { ByteBuffer.wrap(prepareDnsResponse(request).apply {
......
...@@ -23,6 +23,7 @@ package com.github.shadowsocks.net ...@@ -23,6 +23,7 @@ package com.github.shadowsocks.net
import com.github.shadowsocks.utils.parseNumericAddress import com.github.shadowsocks.utils.parseNumericAddress
import net.sourceforge.jsocks.Socks4Message import net.sourceforge.jsocks.Socks4Message
import net.sourceforge.jsocks.Socks5Message import net.sourceforge.jsocks.Socks5Message
import java.io.EOFException
import java.io.IOException import java.io.IOException
import java.net.Inet4Address import java.net.Inet4Address
import java.net.Inet6Address import java.net.Inet6Address
...@@ -69,7 +70,7 @@ class Socks5Endpoint(host: String, port: Int) { ...@@ -69,7 +70,7 @@ class Socks5Endpoint(host: String, port: Int) {
suspend fun readBytes(till: Int) { suspend fun readBytes(till: Int) {
if (buffer.position() >= till) return if (buffer.position() >= till) return
while (reader(buffer) >= 0 && buffer.position() < till) wait() while (reader(buffer) >= 0 && buffer.position() < till) wait()
if (buffer.position() < till) throw IOException("EOF") if (buffer.position() < till) throw EOFException("${buffer.position()} < $till")
} }
suspend fun read(index: Int): Byte { suspend fun read(index: Int): Byte {
readBytes(index + 1) readBytes(index + 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment