gnodet commented on a change in pull request #123:
URL: https://github.com/apache/mina-sshd/pull/123#discussion_r411695349
##########
File path:
sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelAsyncOutputStream.java
##########
@@ -107,9 +108,39 @@ protected synchronized void doWriteIfPossible(boolean
resume) {
if (total > 0) {
Channel channel = getChannel();
Window remoteWindow = channel.getRemoteWindow();
- long length = Math.min(Math.min(remoteWindow.getSize(), total),
remoteWindow.getPacketSize());
- if (log.isTraceEnabled()) {
- log.trace("doWriteIfPossible({})[resume={}] attempting to
write {} out of {}", this, resume, length, total);
+ long length;
+ if (remoteWindow.getSize() < total && total <=
remoteWindow.getPacketSize()) {
+ // do not chunk when the window is smaller than the packet size
+ length = 0;
+ // do a defensive copy in case the user reuses the buffer
+ IoWriteFutureImpl f = new IoWriteFutureImpl(future.getId(),
new ByteArrayBuffer(buffer.getCompactData()));
+ f.addListener(w -> future.setValue(w.getException() != null ?
w.getException() : w.isWritten()));
+ pendingWrite.set(f);
+ if (log.isTraceEnabled()) {
+ log.trace("doWriteIfPossible({})[resume={}] waiting for
window space {}", this, resume,
+ remoteWindow.getSize());
+ }
+ } else if (total > remoteWindow.getPacketSize()) {
+ if (buffer.rpos() > 0) {
+ // do a defensive copy in case the user reuses the buffer
Review comment:
Agreed, I'll split it somehow.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]