Move catch blocks to child classes

This reverts commit 07a48bc20b and f870093c94.
This commit is contained in:
Mygod
2017-12-06 16:07:37 -08:00
parent c50ef11b06
commit e19e629487
6 changed files with 36 additions and 63 deletions
@@ -55,13 +55,18 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
override val socketFile: File = File(filesDir, "protect_path")
override fun accept(socket: LocalSocket) {
socket.inputStream.read()
val fds = socket.ancillaryFileDescriptors
if (fds.isEmpty()) return
val fd = getInt.invoke(fds.first()) as Int
val ret = protect(fd)
JniHelper.close(fd) // Trick to close file decriptor
socket.outputStream.write(if (ret) 0 else 1)
try {
socket.inputStream.read()
val fds = socket.ancillaryFileDescriptors
if (fds.isEmpty()) return
val fd = getInt.invoke(fds.first()) as Int
val ret = protect(fd)
JniHelper.close(fd) // Trick to close file decriptor
socket.outputStream.write(if (ret) 0 else 1)
} catch (e: Exception) {
Log.e(tag, "Error when protect socket", e)
app.track(e)
}
}
}
class NullConnectionException : NullPointerException()