From f4e7085c349fe79fa5744957e26d18a4b035e0c1 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 17 Feb 2023 08:32:59 +0100 Subject: [PATCH] Log non-EPIPE I/O exceptions On close, the client closes the socket. This wakes up socket blocking calls on the server-side, by throwing an exception. Since this exception is expected, it was not logged. However, other IOExceptions might occur, which must not be ignored. For that purpose, log only IOException when they are not caused by an EPIPE error. --- server/src/main/java/com/genymobile/scrcpy/IO.java | 5 +++++ server/src/main/java/com/genymobile/scrcpy/Server.java | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/IO.java b/server/src/main/java/com/genymobile/scrcpy/IO.java index 6eaf0d6a..4a55c152 100644 --- a/server/src/main/java/com/genymobile/scrcpy/IO.java +++ b/server/src/main/java/com/genymobile/scrcpy/IO.java @@ -48,4 +48,9 @@ public final class IO { } return builder.toString(); } + + public static boolean isBrokenPipe(IOException e) { + Throwable cause = e.getCause(); + return cause instanceof ErrnoException && ((ErrnoException) cause).errno == OsConstants.EPIPE; + } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index d7a99576..0aff79bc 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -110,7 +110,10 @@ public final class Server { } screenEncoder.streamScreen(device, videoStreamer); } catch (IOException e) { - // this is expected on close + // Broken pipe is expected on close, because the socket is closed by the client + if (!IO.isBrokenPipe(e)) { + Ln.e("Video encoding error", e); + } } finally { Ln.d("Screen streaming stopped"); initThread.interrupt();