Fix the non delivery of Bye message
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
@@ -259,8 +259,8 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
||||
* @throws IOException if the communication failed */
|
||||
private void communicate(final Socket socket, final PrintWriter writer,
|
||||
BufferedReader in) throws IOException {
|
||||
Thread th = new Thread(new OutputForwardRunnable(writer, socket),
|
||||
"ClientComm"); //$NON-NLS-1$
|
||||
OutputForwardRunnable cc = new OutputForwardRunnable(writer, socket);
|
||||
Thread th = new Thread(cc, "ClientComm"); //$NON-NLS-1$
|
||||
th.start();
|
||||
if (autoClose) {
|
||||
communicateOnce(socket, in);
|
||||
@@ -322,7 +322,14 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
||||
}
|
||||
String ln = reading.getMessage();
|
||||
if (ln.equals(close)) {
|
||||
Thread wait = consoleManager.getWaitForDelivery("Bye."); //$NON-NLS-1$
|
||||
consoleManager.println("Bye."); //$NON-NLS-1$
|
||||
try {
|
||||
wait.join();
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warning("The Bye wait was interrupted."); //$NON-NLS-1$
|
||||
LOGGER.log(Level.FINE, "An interruption occured", e); //$NON-NLS-1$
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Pass command to application
|
||||
|
||||
@@ -85,9 +85,10 @@ public class SocketConsoleApplicationTest {
|
||||
new InputStreamReader(kkSocket.getInputStream()));) {
|
||||
|
||||
String fromServer;
|
||||
int i = 0;
|
||||
int i = -1;
|
||||
String[] cmds = {"help", "toto", "test", "bye"};
|
||||
while ((fromServer = in.readLine()) != null) {
|
||||
i++;
|
||||
LOGGER.fine("Server: \n" + fromServer);
|
||||
if (fromServer.equals("Bye.")) {
|
||||
break;
|
||||
@@ -105,7 +106,6 @@ public class SocketConsoleApplicationTest {
|
||||
LOGGER.fine("Client: " + fromUser);
|
||||
out.println(fromUser);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
assertEquals(4, i);
|
||||
} catch (final IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user