mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-08 16:18:05 +03:00
Try and be helpful on SessionChannel reuse with a more explicit error condition
This commit is contained in:
@@ -50,8 +50,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
/**
|
/**
|
||||||
* {@link Session} implementation.
|
* {@link Session} implementation.
|
||||||
*/
|
*/
|
||||||
public class
|
public class SessionChannel
|
||||||
SessionChannel
|
|
||||||
extends AbstractDirectChannel
|
extends AbstractDirectChannel
|
||||||
implements Session, Session.Command, Session.Shell, Session.Subsystem {
|
implements Session, Session.Command, Session.Shell, Session.Subsystem {
|
||||||
|
|
||||||
@@ -65,6 +64,8 @@ public class
|
|||||||
|
|
||||||
private Boolean canDoFlowControl;
|
private Boolean canDoFlowControl;
|
||||||
|
|
||||||
|
private boolean usedUp;
|
||||||
|
|
||||||
public SessionChannel(Connection conn) {
|
public SessionChannel(Connection conn) {
|
||||||
super(conn, "session");
|
super(conn, "session");
|
||||||
}
|
}
|
||||||
@@ -113,9 +114,11 @@ public class
|
|||||||
@Override
|
@Override
|
||||||
public Command exec(String command)
|
public Command exec(String command)
|
||||||
throws ConnectionException, TransportException {
|
throws ConnectionException, TransportException {
|
||||||
|
checkReuse();
|
||||||
log.info("Will request to exec `{}`", command);
|
log.info("Will request to exec `{}`", command);
|
||||||
sendChannelRequest("exec", true, new Buffer.PlainBuffer().putString(command))
|
sendChannelRequest("exec", true, new Buffer.PlainBuffer().putString(command))
|
||||||
.await(conn.getTimeout(), TimeUnit.SECONDS);
|
.await(conn.getTimeout(), TimeUnit.SECONDS);
|
||||||
|
usedUp = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,16 +200,20 @@ public class
|
|||||||
@Override
|
@Override
|
||||||
public Shell startShell()
|
public Shell startShell()
|
||||||
throws ConnectionException, TransportException {
|
throws ConnectionException, TransportException {
|
||||||
|
checkReuse();
|
||||||
sendChannelRequest("shell", true, null).await(conn.getTimeout(), TimeUnit.SECONDS);
|
sendChannelRequest("shell", true, null).await(conn.getTimeout(), TimeUnit.SECONDS);
|
||||||
|
usedUp = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Subsystem startSubsystem(String name)
|
public Subsystem startSubsystem(String name)
|
||||||
throws ConnectionException, TransportException {
|
throws ConnectionException, TransportException {
|
||||||
|
checkReuse();
|
||||||
log.info("Will request `{}` subsystem", name);
|
log.info("Will request `{}` subsystem", name);
|
||||||
sendChannelRequest("subsystem", true, new Buffer.PlainBuffer().putString(name))
|
sendChannelRequest("subsystem", true, new Buffer.PlainBuffer().putString(name))
|
||||||
.await(conn.getTimeout(), TimeUnit.SECONDS);
|
.await(conn.getTimeout(), TimeUnit.SECONDS);
|
||||||
|
usedUp = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,4 +249,9 @@ public class
|
|||||||
super.notifyError(error);
|
super.notifyError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkReuse() {
|
||||||
|
if (usedUp)
|
||||||
|
throw new SSHRuntimeException("This session channel is all used up");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user