mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 12:05:21 +02:00
RESOLVED - bug 240420: [terminal][ssh]Channel is not closed when the connection is closed with the close button
https://bugs.eclipse.org/bugs/show_bug.cgi?id=240420 Patch https://bugs.eclipse.org/bugs/attachment.cgi?id=107158 applied
This commit is contained in:
parent
9d5e0b002e
commit
18f5afffb1
1 changed files with 26 additions and 9 deletions
|
@ -37,7 +37,6 @@ import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
|
||||||
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
|
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
|
||||||
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
||||||
|
|
||||||
import com.jcraft.jsch.Channel;
|
|
||||||
import com.jcraft.jsch.ChannelShell;
|
import com.jcraft.jsch.ChannelShell;
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import com.jcraft.jsch.Session;
|
import com.jcraft.jsch.Session;
|
||||||
|
@ -48,7 +47,12 @@ class SshConnection extends Thread {
|
||||||
private static int fgNo;
|
private static int fgNo;
|
||||||
private final ITerminalControl fControl;
|
private final ITerminalControl fControl;
|
||||||
private final SshConnector fConn;
|
private final SshConnector fConn;
|
||||||
private Channel fChannel;
|
/**
|
||||||
|
* if true, the terminal has been disconnected. Used to tack
|
||||||
|
* disconnects that happen while the the terminal is still connecting.
|
||||||
|
*/
|
||||||
|
private boolean fDisconnected;
|
||||||
|
private Session fSession;
|
||||||
protected SshConnection(SshConnector conn,ITerminalControl control) {
|
protected SshConnection(SshConnector conn,ITerminalControl control) {
|
||||||
super("SshConnection-"+fgNo++); //$NON-NLS-1$
|
super("SshConnection-"+fgNo++); //$NON-NLS-1$
|
||||||
fControl = control;
|
fControl = control;
|
||||||
|
@ -118,15 +122,22 @@ class SshConnection extends Thread {
|
||||||
session.setServerAliveInterval(nKeepalive); //default is 5 minutes
|
session.setServerAliveInterval(nKeepalive); //default is 5 minutes
|
||||||
}
|
}
|
||||||
session.connect(nTimeout); // making connection with timeout.
|
session.connect(nTimeout); // making connection with timeout.
|
||||||
|
setSession(session);
|
||||||
|
|
||||||
ChannelShell channel=(ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
|
ChannelShell channel=(ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
|
||||||
channel.setPtyType("ansi"); //$NON-NLS-1$
|
channel.setPtyType("ansi"); //$NON-NLS-1$
|
||||||
channel.connect();
|
channel.connect();
|
||||||
setChannel(channel);
|
|
||||||
fConn.setInputStream(channel.getInputStream());
|
fConn.setInputStream(channel.getInputStream());
|
||||||
fConn.setOutputStream(channel.getOutputStream());
|
fConn.setOutputStream(channel.getOutputStream());
|
||||||
fConn.setChannel(channel);
|
fConn.setChannel(channel);
|
||||||
fControl.setState(TerminalState.CONNECTED);
|
fControl.setState(TerminalState.CONNECTED);
|
||||||
|
|
||||||
|
// maybe the terminal was disconnected while we were connecting
|
||||||
|
// if that happened, lets disconnect....
|
||||||
|
if(isDisconnected()) {
|
||||||
|
session.disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// read data until the connection gets terminated
|
// read data until the connection gets terminated
|
||||||
readDataForever(fConn.getInputStream());
|
readDataForever(fConn.getInputStream());
|
||||||
|
@ -138,11 +149,15 @@ class SshConnection extends Thread {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
connectFailed(e.getMessage(),e.getMessage());
|
connectFailed(e.getMessage(),e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
// make sure the terminal is disconnected when the thread ends
|
||||||
|
disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
synchronized void setChannel(Channel channel) {
|
synchronized void setSession(Session session) {
|
||||||
fChannel = channel;
|
fSession = session;
|
||||||
|
}
|
||||||
|
synchronized boolean isDisconnected() {
|
||||||
|
return fDisconnected;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* disconnect the ssh session
|
* disconnect the ssh session
|
||||||
|
@ -150,10 +165,12 @@ class SshConnection extends Thread {
|
||||||
void disconnect() {
|
void disconnect() {
|
||||||
interrupt();
|
interrupt();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if(fChannel!=null) {
|
fDisconnected=true;
|
||||||
fChannel.disconnect();
|
if(fSession!=null) {
|
||||||
fChannel=null;
|
fSession.disconnect();
|
||||||
|
fSession=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue