Fix disconnect notifiers
This commit is contained in:
@@ -385,6 +385,9 @@ public class Telnet3270Client {
|
||||
* Check if connected (any state past TCP pending).
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
if (fsm != null && fsm.getConnectionState() == ConnectionState.NOT_CONNECTED) {
|
||||
return false;
|
||||
}
|
||||
return connection != null && connection.isConnected();
|
||||
}
|
||||
|
||||
|
||||
@@ -599,7 +599,7 @@ public class TelnetConnection {
|
||||
* Check if the socket is connected.
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return socket != null && socket.isConnected() && !socket.isClosed();
|
||||
return running && socket != null && socket.isConnected() && !socket.isClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -654,7 +654,13 @@ public class TelnetConnection {
|
||||
fsm.onError("Network loop error: " + t.getMessage());
|
||||
}
|
||||
} finally {
|
||||
running = false;
|
||||
stopKeepAlive();
|
||||
try {
|
||||
if (socket != null && !socket.isClosed()) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -335,4 +335,24 @@ public class Mock3270ServerIntegrationTest {
|
||||
}
|
||||
assertTrue(receivedWontOrDontTn3270e, "Server should have received Telnet de-negotiation for TN3270E");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServerSideDisconnectTransitionsClientToNotConnectedAndClosesSocket() throws Exception {
|
||||
ConnectionConfig config = new ConnectionConfig("127.0.0.1", server.getPort(), TerminalModel.IBM_3279_2);
|
||||
client = new Telnet3270Client(config);
|
||||
assertTrue(client.connect(8000));
|
||||
assertTrue(server.waitForHandshake(5, TimeUnit.SECONDS));
|
||||
waitForState(client, ConnectionState.CONNECTED_TN3270E, 5000);
|
||||
assertTrue(client.isConnected());
|
||||
|
||||
// Server drops connection (host disconnect)
|
||||
server.disconnectClient();
|
||||
|
||||
// Wait for client to detect disconnect
|
||||
waitForState(client, ConnectionState.NOT_CONNECTED, 5000);
|
||||
assertEquals(ConnectionState.NOT_CONNECTED, client.getConnectionState());
|
||||
assertFalse(client.isConnected(), "Client must report isConnected() == false after host disconnect");
|
||||
assertNotNull(client.getConnection());
|
||||
assertFalse(client.getConnection().isConnected(), "TelnetConnection must report isConnected() == false after host disconnect");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user