Fix interruption mechanic
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
eec660e089
commit
6b2a25674d
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user