Skip to content

Commit 86bc2e6

Browse files
committed
mwiede#411 add flush operation from is/jsch#39, with new config option to allow disabling in case it causes regressions.
1 parent c96ddcf commit 86bc2e6

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/com/jcraft/jsch/Channel.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ static Channel getChannel(String type, Session session) {
6767
ret = new ChannelForwardedTCPIP();
6868
}
6969
if (type.equals("sftp")) {
70-
ret = new ChannelSftp();
70+
ChannelSftp sftp = new ChannelSftp();
71+
boolean useWriteFlushWorkaround =
72+
session.getConfig("use_sftp_write_flush_workaround").equals("yes");
73+
sftp.setUseWriteFlushWorkaround(useWriteFlushWorkaround);
74+
ret = sftp;
7175
}
7276
if (type.equals("subsystem")) {
7377
ret = new ChannelSubsystem();

src/main/java/com/jcraft/jsch/ChannelSftp.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ public class ChannelSftp extends ChannelSession {
157157
private Charset fEncoding = StandardCharsets.UTF_8;
158158
private boolean fEncoding_is_utf8 = true;
159159

160+
private boolean useWriteFlushWorkaround = true;
161+
160162
private RequestQueue rq = new RequestQueue(16);
161163

162164
/**
@@ -181,6 +183,14 @@ public int getBulkRequests() {
181183
return rq.size();
182184
}
183185

186+
public void setUseWriteFlushWorkaround(boolean useWriteFlushWorkaround) {
187+
this.useWriteFlushWorkaround = useWriteFlushWorkaround;
188+
}
189+
190+
public boolean getUseWriteFlushWorkaround() {
191+
return useWriteFlushWorkaround;
192+
}
193+
184194
public ChannelSftp() {
185195
super();
186196
lwsize_max = LOCAL_WINDOW_SIZE_MAX;
@@ -754,6 +764,9 @@ public void write(byte[] d, int s, int len) throws IOException {
754764
try {
755765
int _len = len;
756766
while (_len > 0) {
767+
if (useWriteFlushWorkaround && rwsize < 21 + handle.length + _len + 4) {
768+
flush();
769+
}
757770
int sent = sendWRITE(handle, _offset[0], d, s, _len);
758771
writecount++;
759772
_offset[0] += sent;

src/main/java/com/jcraft/jsch/JSch.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ public class JSch {
228228
config.put("try_additional_pubkey_algorithms",
229229
Util.getSystemProperty("jsch.try_additional_pubkey_algorithms", "yes"));
230230
config.put("enable_auth_none", Util.getSystemProperty("jsch.enable_auth_none", "yes"));
231+
config.put("use_sftp_write_flush_workaround",
232+
Util.getSystemProperty("jsch.use_sftp_write_flush_workaround", "yes"));
231233

232234
config.put("CheckCiphers",
233235
Util.getSystemProperty("jsch.check_ciphers", "chacha20-poly1305@openssh.com"));

src/main/java/com/jcraft/jsch/Session.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,7 @@ private void applyConfig() throws JSchException {
30693069
checkConfig(config, "enable_pubkey_auth_query");
30703070
checkConfig(config, "try_additional_pubkey_algorithms");
30713071
checkConfig(config, "enable_auth_none");
3072+
checkConfig(config, "use_sftp_write_flush_workaround");
30723073

30733074
checkConfig(config, "cipher.c2s");
30743075
checkConfig(config, "cipher.s2c");

0 commit comments

Comments
 (0)