Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sending CHANNEL_EOF message when ChannelOutputStream is closed #554

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class ChannelOutputStream extends OutputStream implements ErrorNoti
private final byte[] b = new byte[1];

private boolean closed;
private boolean signalCloseToRemote = false;
private SSHException error;

private final class DataBuffer {
Expand Down Expand Up @@ -163,7 +164,9 @@ public synchronized void close() throws IOException {
if (!closed) {
try {
buffer.flush(false);
// trans.write(new SSHPacket(Message.CHANNEL_EOF).putUInt32(chan.getRecipient()));
if (signalCloseToRemote) {
trans.write(new SSHPacket(Message.CHANNEL_EOF).putUInt32(chan.getRecipient()));
}
} finally {
closed = true;
}
Expand All @@ -187,4 +190,20 @@ public String toString() {
return "< ChannelOutputStream for Channel #" + chan.getID() + " >";
}

public boolean isSignalCloseToRemote() {
return signalCloseToRemote;
}

/**
* @param signalCloseToRemote <code>true</code>: when calling {@link #close()} the remote side will be informed
* that no further input will be received. Effectively this means that the remote
* command will get an EOF on stdin. This is only important for remote commands that
* process data from stdin (e.g. files) and do not terminate until they get an EOF for
* stdin.
* <p>
* By default the remote side will not be informed that the stream has been closed.
*/
public void setSignalCloseToRemote(boolean signalCloseToRemote) {
this.signalCloseToRemote = signalCloseToRemote;
}
}