From 37af0c80765b01ed349f843032b2131690e0cd66 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 16 Feb 2018 14:13:13 +0100 Subject: [PATCH] Terminate event controller thread on EOF No exception was thrown on EOF, so the event controller did not terminate. This leaded to a further InvocationTargetException. Instead, terminate the event controller on EOF, so that the process terminates properly. --- .../java/com/genymobile/scrcpy/ControlEventReader.java | 6 +++--- .../src/main/java/com/genymobile/scrcpy/ScrCpyServer.java | 8 -------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java b/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java index 4d412f9b..c752c6cd 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java +++ b/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java @@ -1,5 +1,6 @@ package com.genymobile.scrcpy; +import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -28,7 +29,7 @@ public class ControlEventReader { return buffer.remaining() == rawBuffer.length; } - public boolean readFrom(InputStream input) throws IOException { + public void readFrom(InputStream input) throws IOException { if (isFull()) { throw new IllegalStateException("Buffer full, call next() to consume"); } @@ -36,11 +37,10 @@ public class ControlEventReader { int head = buffer.position(); int r = input.read(rawBuffer, head, rawBuffer.length - head); if (r == -1) { - return false; + throw new EOFException("Event controller socket closed"); } buffer.position(head + r); buffer.flip(); - return true; } public ControlEvent next() { diff --git a/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java b/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java index 61f84451..1476d22f 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java @@ -1,7 +1,6 @@ package com.genymobile.scrcpy; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; public final class ScrCpyServer { @@ -63,13 +62,6 @@ public final class ScrCpyServer { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { - if (e instanceof AssertionError && e.getCause() instanceof InvocationTargetException) { - // WORKAROUND - // When we call a method of the framework by reflection, it may throw an InvocationTargetException - // (that we wrap into an AssertionError) if this process is being killed. - // To avoid the stacktrace on close, do not log these errors. - return; - } Ln.e("Exception on thread " + t, e); } });