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 2013/02/09 17:07:50 UTC

svn commit: r1444384 - in /httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor: AbstractMultiworkerIOReactor.java DefaultListeningIOReactor.java IOReactorConfig.java

Author: olegk
Date: Sat Feb  9 16:07:50 2013
New Revision: 1444384

URL: http://svn.apache.org/r1444384
Log:
Added sndBufSize / rcvBufSize parameters to IOReactorConfig

Modified:
    httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
    httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
    httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java

Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=1444384&r1=1444383&r2=1444384&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java Sat Feb  9 16:07:50 2013
@@ -523,8 +523,17 @@ public abstract class AbstractMultiworke
      */
     protected void prepareSocket(final Socket socket) throws IOException {
         socket.setTcpNoDelay(this.config.isTcpNoDelay());
-        socket.setSoTimeout(this.config.getSoTimeout());
         socket.setKeepAlive(this.config.isSoKeepalive());
+        socket.setReuseAddress(this.config.isSoReuseAddress());
+        if (this.config.getSoTimeout() > 0) {
+            socket.setSoTimeout(this.config.getSoTimeout());
+        }
+        if (this.config.getSndBufSize() > 0) {
+            socket.setSendBufferSize(this.config.getSndBufSize());
+        }
+        if (this.config.getRcvBufSize() > 0) {
+            socket.setReceiveBufferSize(this.config.getRcvBufSize());
+        }
         int linger = this.config.getSoLinger();
         if (linger >= 0) {
             socket.setSoLinger(linger > 0, linger);

Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java?rev=1444384&r1=1444383&r2=1444384&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java Sat Feb  9 16:07:50 2013
@@ -28,6 +28,7 @@
 package org.apache.http.impl.nio.reactor;
 
 import java.io.IOException;
+import java.net.ServerSocket;
 import java.net.SocketAddress;
 import java.nio.channels.CancelledKeyException;
 import java.nio.channels.SelectionKey;
@@ -231,8 +232,10 @@ public class DefaultListeningIOReactor e
                 throw new IOReactorException("Failure opening server socket", ex);
             }
             try {
+                ServerSocket socket = serverChannel.socket();
+                socket.setReuseAddress(this.config.isSoReuseAddress());
                 serverChannel.configureBlocking(false);
-                serverChannel.socket().bind(address);
+                socket.bind(address);
             } catch (IOException ex) {
                 closeChannel(serverChannel);
                 request.failed(ex);

Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java?rev=1444384&r1=1444383&r2=1444384&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java Sat Feb  9 16:07:50 2013
@@ -41,7 +41,7 @@ import org.apache.http.annotation.NotThr
 public final class IOReactorConfig implements Cloneable {
 
     private static final int AVAIL_PROCS = Runtime.getRuntime().availableProcessors();
-    
+
     private long selectInterval;
     private long shutdownGracePeriod;
     private boolean interestOpQueued;
@@ -52,6 +52,8 @@ public final class IOReactorConfig imple
     private boolean soKeepAlive;
     private boolean tcpNoDelay;
     private int connectTimeout;
+    private int sndBufSize;
+    private int rcvBufSize;
 
     public IOReactorConfig() {
         super();
@@ -285,6 +287,50 @@ public final class IOReactorConfig imple
         this.connectTimeout = connectTimeout;
     }
 
+    /**
+     * Determines the default value of the {@link SocketOptions#SO_SNDBUF} parameter
+     * for newly created sockets.
+     * <p/>
+     * Default: <code>0</code> (system default)
+     *
+     * @see SocketOptions#SO_SNDBUF
+     */
+    public int getSndBufSize() {
+        return sndBufSize;
+    }
+
+    /**
+     * Defines the default value of the {@link SocketOptions#SO_SNDBUF} parameter
+     * for newly created sockets.
+     *
+     * @see SocketOptions#SO_SNDBUF
+     */
+    public void setSndBufSize(int sndBufSize) {
+        this.sndBufSize = sndBufSize;
+    }
+
+    /**
+     * Determines the default value of the {@link SocketOptions#SO_RCVBUF} parameter
+     * for newly created sockets.
+     * <p/>
+     * Default: <code>0</code> (system default)
+     *
+     * @see SocketOptions#SO_RCVBUF
+     */
+    public int getRcvBufSize() {
+        return rcvBufSize;
+    }
+
+    /**
+     * Defines the default value of the {@link SocketOptions#SO_RCVBUF} parameter
+     * for newly created sockets.
+     *
+     * @see SocketOptions#SO_RCVBUF
+     */
+    public void setRcvBufSize(int rcvBufSize) {
+        this.rcvBufSize = rcvBufSize;
+    }
+
     @Override
     protected IOReactorConfig clone() throws CloneNotSupportedException {
         return (IOReactorConfig) super.clone();
@@ -302,7 +348,10 @@ public final class IOReactorConfig imple
                 .append(", soLinger=").append(this.soLinger)
                 .append(", soKeepAlive=").append(this.soKeepAlive)
                 .append(", tcpNoDelay=").append(this.tcpNoDelay)
-                .append(", connectTimeout=").append(this.connectTimeout).append("]");
+                .append(", connectTimeout=").append(this.connectTimeout)
+                .append(", sndBufSize=").append(this.sndBufSize)
+                .append(", rcvBufSize=").append(this.rcvBufSize)
+                .append("]");
         return builder.toString();
     }