mirror of https://github.com/Genymobile/scrcpy
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.
This commit is contained in:
parent
ad6209f6ff
commit
37af0c8076
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue