diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java index f846547..c77d719 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java @@ -196,6 +196,10 @@ public final class ConnectingConsoleInput implements ConsoleInput { while (true) { synchronized (promptLock) { if (!prompting) { + if (interrupting) { + interrupting = false; + throw new InterruptedIOException("Prompt was interrupted"); + } return null; } } @@ -211,6 +215,7 @@ public final class ConnectingConsoleInput implements ConsoleInput { final String res = actualConnected.prompt(message); synchronized (promptLock) { if (prompting) { + prompting = false; return res; } } @@ -235,13 +240,17 @@ public final class ConnectingConsoleInput implements ConsoleInput { if (timeout <= 0) { return prompt(message); } - final long end = System.currentTimeMillis() + timeout; synchronized (promptLock) { prompting = true; } + final long end = System.currentTimeMillis() + timeout; do { synchronized (promptLock) { if (!prompting) { + if (interrupting) { + interrupting = false; + throw new InterruptedIOException("Prompt was interrupted"); + } break; } } @@ -253,28 +262,28 @@ public final class ConnectingConsoleInput implements ConsoleInput { actualConnected = connected; } if (connect) { - synchronized (promptLock) { - try { - final String res = actualConnected.prompt(message, - end - System.currentTimeMillis()); + try { + final String res = actualConnected.prompt(message, + end - System.currentTimeMillis()); + synchronized (promptLock) { if (prompting) { + prompting = false; return res; } - } catch (final InterruptedIOException e) { - // The inner console was interrupted. This can mean we are - // disconnecting or actually interrupted. - if (disconnection) { - disconnection = false; - } else { - throw e; - } - + } + } catch (final InterruptedIOException e) { + // The inner console was interrupted. This can mean we are + // disconnecting or actually interrupted. + if (disconnection) { + disconnection = false; + } else { + interrupting = false; + throw e; } } } } while (System.currentTimeMillis() < end); return null; - } private void getConnection(final long timeout) throws InterruptedIOException {