Skip to content

Commit

Permalink
mwiede#411 add flush operation from is/jsch#39, with new config optio…
Browse files Browse the repository at this point in the history
…n to allow disabling in case it causes regressions.
  • Loading branch information
norrisjeremy committed Nov 13, 2023
1 parent c96ddcf commit 86bc2e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/com/jcraft/jsch/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ static Channel getChannel(String type, Session session) {
ret = new ChannelForwardedTCPIP();
}
if (type.equals("sftp")) {
ret = new ChannelSftp();
ChannelSftp sftp = new ChannelSftp();
boolean useWriteFlushWorkaround =
session.getConfig("use_sftp_write_flush_workaround").equals("yes");
sftp.setUseWriteFlushWorkaround(useWriteFlushWorkaround);
ret = sftp;
}
if (type.equals("subsystem")) {
ret = new ChannelSubsystem();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/jcraft/jsch/ChannelSftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public class ChannelSftp extends ChannelSession {
private Charset fEncoding = StandardCharsets.UTF_8;
private boolean fEncoding_is_utf8 = true;

private boolean useWriteFlushWorkaround = true;

private RequestQueue rq = new RequestQueue(16);

/**
Expand All @@ -181,6 +183,14 @@ public int getBulkRequests() {
return rq.size();
}

public void setUseWriteFlushWorkaround(boolean useWriteFlushWorkaround) {
this.useWriteFlushWorkaround = useWriteFlushWorkaround;
}

public boolean getUseWriteFlushWorkaround() {
return useWriteFlushWorkaround;
}

public ChannelSftp() {
super();
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
Expand Down Expand Up @@ -754,6 +764,9 @@ public void write(byte[] d, int s, int len) throws IOException {
try {
int _len = len;
while (_len > 0) {
if (useWriteFlushWorkaround && rwsize < 21 + handle.length + _len + 4) {
flush();
}
int sent = sendWRITE(handle, _offset[0], d, s, _len);
writecount++;
_offset[0] += sent;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jcraft/jsch/JSch.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ public class JSch {
config.put("try_additional_pubkey_algorithms",
Util.getSystemProperty("jsch.try_additional_pubkey_algorithms", "yes"));
config.put("enable_auth_none", Util.getSystemProperty("jsch.enable_auth_none", "yes"));
config.put("use_sftp_write_flush_workaround",
Util.getSystemProperty("jsch.use_sftp_write_flush_workaround", "yes"));

config.put("CheckCiphers",
Util.getSystemProperty("jsch.check_ciphers", "[email protected]"));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jcraft/jsch/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -3069,6 +3069,7 @@ private void applyConfig() throws JSchException {
checkConfig(config, "enable_pubkey_auth_query");
checkConfig(config, "try_additional_pubkey_algorithms");
checkConfig(config, "enable_auth_none");
checkConfig(config, "use_sftp_write_flush_workaround");

checkConfig(config, "cipher.c2s");
checkConfig(config, "cipher.s2c");
Expand Down

0 comments on commit 86bc2e6

Please sign in to comment.