You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/04/25 15:33:17 UTC

svn commit: r1590024 - in /httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http: config/SocketConfig.java impl/pool/BasicConnFactory.java

Author: olegk
Date: Fri Apr 25 13:33:17 2014
New Revision: 1590024

URL: http://svn.apache.org/r1590024
Log:
Added SO_SNDBUF and SO_RCVBUF socket config parameters

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/config/SocketConfig.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/config/SocketConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/config/SocketConfig.java?rev=1590024&r1=1590023&r2=1590024&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/config/SocketConfig.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/config/SocketConfig.java Fri Apr 25 13:33:17 2014
@@ -45,19 +45,25 @@ public class SocketConfig implements Clo
     private final int soLinger;
     private final boolean soKeepAlive;
     private final boolean tcpNoDelay;
+    private final int sndBufSize;
+    private final int rcvBufSize;
 
     SocketConfig(
             final int soTimeout,
             final boolean soReuseAddress,
             final int soLinger,
             final boolean soKeepAlive,
-            final boolean tcpNoDelay) {
+            final boolean tcpNoDelay,
+            final int sndBufSize,
+            final int rcvBufSize) {
         super();
         this.soTimeout = soTimeout;
         this.soReuseAddress = soReuseAddress;
         this.soLinger = soLinger;
         this.soKeepAlive = soKeepAlive;
         this.tcpNoDelay = tcpNoDelay;
+        this.sndBufSize = sndBufSize;
+        this.rcvBufSize = rcvBufSize;
     }
 
     /**
@@ -104,7 +110,7 @@ public class SocketConfig implements Clo
      * @see java.net.SocketOptions#SO_KEEPALIVE
      */
     public boolean isSoKeepAlive() {
-        return this.soKeepAlive;
+        return soKeepAlive;
     }
 
     /**
@@ -119,6 +125,34 @@ public class SocketConfig implements Clo
         return tcpNoDelay;
     }
 
+    /**
+     * Determines the default value of the {@link java.net.SocketOptions#SO_SNDBUF} parameter
+     * for newly created sockets.
+     * <p/>
+     * Default: <code>0</code> (system default)
+     *
+     * @see java.net.SocketOptions#SO_SNDBUF
+     *
+     * @since 4.4
+     */
+    public int getSndBufSize() {
+        return sndBufSize;
+    }
+
+    /**
+     * Determines the default value of the {@link java.net.SocketOptions#SO_RCVBUF} parameter
+     * for newly created sockets.
+     * <p/>
+     * Default: <code>0</code> (system default)
+     *
+     * @see java.net.SocketOptions#SO_RCVBUF
+     *
+     * @since 4.4
+     */
+    public int getRcvBufSize() {
+        return rcvBufSize;
+    }
+
     @Override
     protected SocketConfig clone() throws CloneNotSupportedException {
         return (SocketConfig) super.clone();
@@ -132,6 +166,8 @@ public class SocketConfig implements Clo
                 .append(", soLinger=").append(this.soLinger)
                 .append(", soKeepAlive=").append(this.soKeepAlive)
                 .append(", tcpNoDelay=").append(this.tcpNoDelay)
+                .append(", sndBufSize=").append(this.sndBufSize)
+                .append(", rcvBufSize=").append(this.rcvBufSize)
                 .append("]");
         return builder.toString();
     }
@@ -147,7 +183,9 @@ public class SocketConfig implements Clo
             .setSoReuseAddress(config.isSoReuseAddress())
             .setSoLinger(config.getSoLinger())
             .setSoKeepAlive(config.isSoKeepAlive())
-            .setTcpNoDelay(config.isTcpNoDelay());
+            .setTcpNoDelay(config.isTcpNoDelay())
+            .setSndBufSize(config.getSndBufSize())
+            .setRcvBufSize(config.getRcvBufSize());
     }
 
     public static class Builder {
@@ -157,6 +195,8 @@ public class SocketConfig implements Clo
         private int soLinger;
         private boolean soKeepAlive;
         private boolean tcpNoDelay;
+        private int sndBufSize;
+        private int rcvBufSize;
 
         Builder() {
             this.soLinger = -1;
@@ -188,8 +228,25 @@ public class SocketConfig implements Clo
             return this;
         }
 
+        /**
+         * @since 4.4
+         */
+        public Builder setSndBufSize(final int sndBufSize) {
+            this.sndBufSize = sndBufSize;
+            return this;
+        }
+
+        /**
+         * @since 4.4
+         */
+        public Builder setRcvBufSize(final int rcvBufSize) {
+            this.rcvBufSize = rcvBufSize;
+            return this;
+        }
+
         public SocketConfig build() {
-            return new SocketConfig(soTimeout, soReuseAddress, soLinger, soKeepAlive, tcpNoDelay);
+            return new SocketConfig(soTimeout, soReuseAddress, soLinger, soKeepAlive, tcpNoDelay,
+                    sndBufSize, rcvBufSize);
         }
 
     }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java?rev=1590024&r1=1590023&r2=1590024&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java Fri Apr 25 13:33:17 2014
@@ -167,6 +167,12 @@ public class BasicConnFactory implements
         socket.setSoTimeout(this.sconfig.getSoTimeout());
         socket.connect(new InetSocketAddress(hostname, port), this.connectTimeout);
         socket.setTcpNoDelay(this.sconfig.isTcpNoDelay());
+        if (this.sconfig.getSndBufSize() > 0) {
+            socket.setSendBufferSize(this.sconfig.getSndBufSize());
+        }
+        if (this.sconfig.getRcvBufSize() > 0) {
+            socket.setReceiveBufferSize(this.sconfig.getRcvBufSize());
+        }
         final int linger = this.sconfig.getSoLinger();
         if (linger >= 0) {
             socket.setSoLinger(true, linger);