From cf11e7db62afbca269e6fa1777c131c9bbdbe805 Mon Sep 17 00:00:00 2001 From: Ethan Chapman Date: Tue, 29 Oct 2024 19:07:11 -0400 Subject: [PATCH] Move broken pipe exception handling If it's somehow not actually triggered in close(), the more invasive message is beneficial. send*() methods should be consistent in exception handling anyways. --- .../java/chokistream/ChirunoModClient.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/chokistream/ChirunoModClient.java b/src/main/java/chokistream/ChirunoModClient.java index ffccfde..ff90a89 100644 --- a/src/main/java/chokistream/ChirunoModClient.java +++ b/src/main/java/chokistream/ChirunoModClient.java @@ -133,21 +133,7 @@ public void sendInit() throws IOException { public void sendDisconnect() throws IOException { logger.log("Sending disconnect packet", LogLevel.VERBOSE); - try { - out.write((new Packet((byte)0x03, (byte)0x00, new byte[] {})).pack); - } catch (SocketException e) { - /** - * Refer to docs. - * https://github.com/Eiim/Chokistream/wiki/Technical-info-on-bugs-and-quirks/_edit#issues-with-luma3ds-control-wireless-connection-hack - * todo: investigate */ - if(e.getMessage().contains("Broken pipe")) { - // do something? - } - - logger.log("ChirunoModClient.sendDisconnect() warning: "+e.getClass()+": "+e.getMessage()); - logger.log(Arrays.toString(e.getStackTrace()), LogLevel.VERBOSE); - logger.log("The 3DS seems to have already disconnected"); - } + out.write((new Packet((byte)0x03, (byte)0x00, new byte[] {})).pack); } // We don't really have a use for this yet but might as well support it @@ -221,7 +207,21 @@ public void switchScreen() throws IOException { @Override public void close() throws IOException { - sendDisconnect(); + try { + sendDisconnect(); + } catch (SocketException e) { + if(e.getMessage().contains("Broken pipe")) { + /* + * Documented here: https://github.com/Eiim/Chokistream/wiki/Technical-info-on-bugs-and-quirks/_edit#issues-with-luma3ds-control-wireless-connection-hack + * TODO: investigate, possibly handle more cleanly or fix + */ + logger.log("ChirunoModClient.close() warning: "+e.getClass()+": "+e.getMessage()); + logger.log(Arrays.toString(e.getStackTrace()), LogLevel.VERBOSE); + logger.log("The 3DS seems to have already disconnected"); + } else { + throw e; + } + } in.close(); out.close(); client.close();