From 1c5a171cc468ddbc0ce6669f3854b1beb8e5e77c Mon Sep 17 00:00:00 2001 From: Michael Scharf Date: Tue, 27 Feb 2007 04:35:53 +0000 Subject: [PATCH] [174955] Terminal should go to "disconnected" state when typing "exit" Simplified the read loop and check for InterruptedIOException... --- .../internal/terminal/ssh/SshConnection.java | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java index 86edfbfdfcc..ab537ac7022 100644 --- a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java +++ b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java @@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.ssh; import java.io.IOException; import java.io.InputStream; +import java.io.InterruptedIOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; @@ -240,8 +241,12 @@ class SshConnection extends Thread { fConn.setOutputStream(channel.getOutputStream()); fConn.setChannel(channel); fControl.setState(TerminalState.CONNECTED); - // read data until the connection gets terminated - readDataForever(fConn.getInputStream()); + try { + // read data until the connection gets terminated + readDataForever(fConn.getInputStream()); + } catch (InterruptedIOException e) { + // we got interrupted: we are done... + } // when reading is done, we set the state to closed fControl.setState(TerminalState.CLOSED); } catch (JSchException e) { @@ -275,23 +280,9 @@ class SshConnection extends Thread { private void readDataForever(InputStream in) throws IOException { // read the data byte bytes[]=new byte[32*1024]; + int n; // read until the thread gets interrupted.... - while(!isInterrupted()) { - int n; - // We have to poll. There seems no better way to cancel - // the read from ssh.... - while(in.available()==0) { - try { - sleep(1); - } catch (InterruptedException e) { - // propagate the interrupt - interrupt(); - return; - } - } - // read some bytes - if((n=in.read(bytes))==-1) - return; + while( (n=in.read(bytes))!=-1) { // we assume we get ASCII UTF8 bytes fControl.writeToTerminal(new String(bytes,0,n,"UTF8")); //$NON-NLS-1$ }