mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
[174955] Terminal should go to "disconnected" state when typing "exit"
Simplified the read loop and check for InterruptedIOException...
This commit is contained in:
parent
6858d22f8b
commit
1c5a171cc4
1 changed files with 9 additions and 18 deletions
|
@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.ssh;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -240,8 +241,12 @@ class SshConnection extends Thread {
|
||||||
fConn.setOutputStream(channel.getOutputStream());
|
fConn.setOutputStream(channel.getOutputStream());
|
||||||
fConn.setChannel(channel);
|
fConn.setChannel(channel);
|
||||||
fControl.setState(TerminalState.CONNECTED);
|
fControl.setState(TerminalState.CONNECTED);
|
||||||
// read data until the connection gets terminated
|
try {
|
||||||
readDataForever(fConn.getInputStream());
|
// 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
|
// when reading is done, we set the state to closed
|
||||||
fControl.setState(TerminalState.CLOSED);
|
fControl.setState(TerminalState.CLOSED);
|
||||||
} catch (JSchException e) {
|
} catch (JSchException e) {
|
||||||
|
@ -275,23 +280,9 @@ class SshConnection extends Thread {
|
||||||
private void readDataForever(InputStream in) throws IOException {
|
private void readDataForever(InputStream in) throws IOException {
|
||||||
// read the data
|
// read the data
|
||||||
byte bytes[]=new byte[32*1024];
|
byte bytes[]=new byte[32*1024];
|
||||||
|
int n;
|
||||||
// read until the thread gets interrupted....
|
// read until the thread gets interrupted....
|
||||||
while(!isInterrupted()) {
|
while( (n=in.read(bytes))!=-1) {
|
||||||
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;
|
|
||||||
// we assume we get ASCII UTF8 bytes
|
// we assume we get ASCII UTF8 bytes
|
||||||
fControl.writeToTerminal(new String(bytes,0,n,"UTF8")); //$NON-NLS-1$
|
fControl.writeToTerminal(new String(bytes,0,n,"UTF8")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue