You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by GitBox <gi...@apache.org> on 2020/09/14 10:59:38 UTC

[GitHub] [mina-sshd] gnodet commented on a change in pull request #166: [SSHD-1070] Limit the amount of data that is kept in memory for forwa…

gnodet commented on a change in pull request #166:
URL: https://github.com/apache/mina-sshd/pull/166#discussion_r487826081



##########
File path: sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
##########
@@ -217,9 +225,23 @@ public void messageReceived(IoSession session, Readable message) throws Exceptio
                         log.debug("doInit({}) Ignoring write to channel in CLOSING state", TcpipServerChannel.this);
                     }
                 } else {
-                    Buffer buffer = new ByteArrayBuffer(message.available(), false);
+                    int length = message.available();
+                    Buffer buffer = new ByteArrayBuffer(length, false);
                     buffer.putBuffer(message);
-                    out.writePacket(buffer);
+                    long total = inFlightDataSize.addAndGet(length);
+                    if (total > maxBufferSize) {
+                        session.suspendRead();
+                    }
+                    IoWriteFuture ioWriteFuture = out.writePacket(buffer);
+                    ioWriteFuture.addListener(new SshFutureListener<IoWriteFuture>() {
+                        @Override
+                        public void operationComplete(IoWriteFuture future) {
+                            long total = inFlightDataSize.addAndGet(-length);
+                            if (total <= maxBufferSize) {

Review comment:
       Right, that makes sense, I'll split the property.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org