You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/07/27 10:32:56 UTC

[2/2] mina-sshd git commit: Avoid re-creating growth functions repeatedly

Avoid re-creating growth functions repeatedly


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/9521dfa2
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/9521dfa2
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/9521dfa2

Branch: refs/heads/master
Commit: 9521dfa27498ef718920a85aaf3d195243e46ee2
Parents: 3c2a466
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Jul 27 11:32:46 2015 +0300
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Jul 27 11:32:46 2015 +0300

----------------------------------------------------------------------
 .../java/org/apache/sshd/common/channel/AbstractChannel.java | 7 ++++++-
 .../sshd/common/session/AbstractConnectionService.java       | 7 ++++++-
 .../apache/sshd/server/global/CancelTcpipForwardHandler.java | 7 ++++++-
 .../org/apache/sshd/server/global/TcpipForwardHandler.java   | 8 +++++++-
 4 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9521dfa2/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index 7b613f5..4c24645 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -59,6 +59,11 @@ public abstract class AbstractChannel
 
     public static final long DEFAULT_CHANNEL_CLOSE_TIMEOUT = 5000;
 
+    /**
+     * Default growth factor function used to resize response buffers
+     */
+    public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.Utils.add(Byte.SIZE);
+
     protected static enum GracefulState {
         Opened, CloseSent, CloseReceived, Closed
     }
@@ -181,7 +186,7 @@ public abstract class AbstractChannel
                  : SshConstants.SSH_MSG_CHANNEL_FAILURE;
         buffer.clear();
         // leave room for the SSH header
-        buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), Int2IntFunction.Utils.add(Byte.SIZE));
+        buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), RESPONSE_BUFFER_GROWTH_FACTOR);
         buffer.rpos(5);
         buffer.wpos(5);
         buffer.putByte(cmd);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9521dfa2/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
index 48b3a0a..939d283 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
@@ -76,6 +76,11 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
     public static final int DEFAULT_MAX_CHANNELS = Integer.MAX_VALUE;
 
     /**
+     * Default growth factor function used to resize response buffers
+     */
+    public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.Utils.add(Byte.SIZE);
+
+    /**
      * Map of channels keyed by the identifier
      */
     protected final Map<Integer, Channel> channels = new ConcurrentHashMap<>();
@@ -472,7 +477,7 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
                  : SshConstants.SSH_MSG_CHANNEL_FAILURE;
         buffer.clear();
         // leave room for the SSH header
-        buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), Int2IntFunction.Utils.add(Byte.SIZE));
+        buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), RESPONSE_BUFFER_GROWTH_FACTOR);
         buffer.rpos(5);
         buffer.wpos(5);
         buffer.putByte(cmd);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9521dfa2/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
index b68d54b..483b0cb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
@@ -35,6 +35,11 @@ import org.apache.sshd.common.util.logging.AbstractLoggingBean;
  */
 public class CancelTcpipForwardHandler extends AbstractLoggingBean implements ConnectionServiceRequestHandler {
     public static final String REQUEST = "cancel-tcpip-forward";
+    /**
+     * Default growth factor function used to resize response buffers
+     */
+    public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.Utils.add(Byte.SIZE);
+
     public static final CancelTcpipForwardHandler INSTANCE = new CancelTcpipForwardHandler();
 
     public CancelTcpipForwardHandler() {
@@ -57,7 +62,7 @@ public class CancelTcpipForwardHandler extends AbstractLoggingBean implements Co
             if (wantReply) {
                 buffer.clear();
                 // leave room for the SSH header
-                buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), Int2IntFunction.Utils.add(Byte.SIZE));
+                buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), RESPONSE_BUFFER_GROWTH_FACTOR);
                 buffer.rpos(5);
                 buffer.wpos(5);
                 buffer.putByte(SshConstants.SSH_MSG_REQUEST_SUCCESS);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9521dfa2/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
index 4b0f0c4..c554f3b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
@@ -35,6 +35,12 @@ import org.apache.sshd.common.util.logging.AbstractLoggingBean;
  */
 public class TcpipForwardHandler extends AbstractLoggingBean implements ConnectionServiceRequestHandler {
     public static final String REQUEST = "tcpip-forward";
+
+    /**
+     * Default growth factor function used to resize response buffers
+     */
+    public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR = Int2IntFunction.Utils.add(Byte.SIZE);
+
     public static final TcpipForwardHandler INSTANCE = new TcpipForwardHandler();
 
     public TcpipForwardHandler() {
@@ -57,7 +63,7 @@ public class TcpipForwardHandler extends AbstractLoggingBean implements Connecti
             if (wantReply) {
                 buffer.clear();
                 // leave room for the SSH header
-                buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), Int2IntFunction.Utils.add(Byte.SIZE));
+                buffer.ensureCapacity(5 + 1 + (Integer.SIZE / Byte.SIZE), RESPONSE_BUFFER_GROWTH_FACTOR);
                 buffer.rpos(5);
                 buffer.wpos(5);
                 buffer.putByte(SshConstants.SSH_MSG_REQUEST_SUCCESS);