Close connection during ExecChannel

This commit is contained in:
Nikolay Sokolov 2015-06-16 19:43:05 +03:00 committed by Ignasi Barrera
parent 502d96d22b
commit 060b66a4f7
2 changed files with 11 additions and 7 deletions

View File

@ -48,9 +48,7 @@ public interface SshClient {
ExecResponse exec(String command);
/**
* Execute a process and allow the user to interact with it. Note that this will allow the
* session to exist indefinitely, and its connection is not closed when {@link #disconnect()} is
* called.
* Execute a process and allow the user to interact with it.
*
* @param command
* command line to invoke

View File

@ -511,8 +511,8 @@ public class SshjSshClient implements SshClient {
class ExecChannelConnection implements Connection<ExecChannel> {
private final String command;
private SessionChannel session;
private Command output;
private Connection<Session> connection;
ExecChannelConnection(String command) {
this.command = checkNotNull(command, "command");
@ -521,13 +521,19 @@ public class SshjSshClient implements SshClient {
@Override
public void clear() {
Closeables2.closeQuietly(output);
Closeables2.closeQuietly(session);
try {
if (connection != null) {
connection.clear();
}
} catch (Throwable e) {
Throwables.propagate(e);
}
}
@Override
public ExecChannel create() throws Exception {
session = SessionChannel.class.cast(acquire(noPTYConnection()));
output = session.exec(command);
connection = noPTYConnection();
output = SessionChannel.class.cast(acquire(connection)).exec(command);
return new ExecChannel(output.getOutputStream(), output.getInputStream(), output.getErrorStream(),
new Supplier<Integer>() {