You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by sp...@apache.org on 2010/01/09 03:45:45 UTC
svn commit: r897373 -
/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
Author: spearce
Date: Sat Jan 9 02:45:45 2010
New Revision: 897373
URL: http://svn.apache.org/viewvc?rev=897373&view=rev
Log:
Correctly compute the lastSize member in ChannelOutputStream
If we have to split the current Buffer, because its too large for
the session's window or packet size, don't give ourselves a credit
equal to the left over portion. Instead use the actual number of
bytes we transmit inside of flush.
However, because we know the new Buffer needs to hold at least
a certain size, we can allocate it in advance to that target,
to avoid needing to grow it while doing the split.
Modified:
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java?rev=897373&r1=897372&r2=897373&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelOutputStream.java Sat Jan 9 02:45:45 2010
@@ -48,7 +48,7 @@
this.remoteWindow = remoteWindow;
this.log = log;
this.cmd = cmd;
- newBuffer();
+ newBuffer(0);
}
public synchronized void write(int w) throws IOException {
@@ -94,12 +94,15 @@
buf.wpos(cmd == SshConstants.Message.SSH_MSG_CHANNEL_EXTENDED_DATA ? 14 : 10);
buf.putInt(length);
buf.wpos(buf.wpos() + length);
- lastSize = Math.max(length, total - length);
- newBuffer();
- if (total > length) {
- buffer.putRawBytes(buf.array(), pos - (total - length), total - length);
- bufferLength = total - length;
+ if (total == length) {
+ newBuffer(length);
+ } else {
+ int leftover = total - length;
+ newBuffer(Math.max(leftover, length));
+ buffer.putRawBytes(buf.array(), pos - leftover, leftover);
+ bufferLength = leftover;
}
+ lastSize = length;
remoteWindow.waitAndConsume(length);
log.debug("Send {} on channel {}", cmd, channel.getId());
channel.getSession().writePacket(buf);
@@ -119,8 +122,8 @@
closed = true;
}
- private void newBuffer() {
- buffer = channel.getSession().createBuffer(cmd, lastSize <= 0 ? 0 : 12 + lastSize);
+ private void newBuffer(int size) {
+ buffer = channel.getSession().createBuffer(cmd, size <= 0 ? 0 : 12 + size);
buffer.putInt(channel.getRecipient());
if (cmd == SshConstants.Message.SSH_MSG_CHANNEL_EXTENDED_DATA) {
buffer.putInt(1);