hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r903779 - in /httpcomponents/httpcore/trunk: ./ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ httpcore/src/main/java/org/apache/http/params/
Date Wed, 27 Jan 2010 18:29:08 GMT
Author: olegk
Date: Wed Jan 27 18:29:07 2010
New Revision: 903779

URL: http://svn.apache.org/viewvc?rev=903779&view=rev
Log:
HTTPCORE-209: Added parameter to set SO_REUSEADDR on sockets bound to a local address

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/CoreConnectionPNames.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpConnectionParams.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=903779&r1=903778&r2=903779&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Wed Jan 27 18:29:07 2010
@@ -1,5 +1,8 @@
 Changes since 4.1-ALPHA1
 
+* [HTTPCORE-209] Added parameter to set SO_REUSEADDR on sockets bound to a local address.
+  Contributed by Oleg Kalnichevski <olegk at apache.org> 
+
 * [HTTPCORE-207] SocketHttp*Connection classes can leak sockets if the connection is half-closed
   Contributed by David Koski <david_koski at mac.com>
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java?rev=903779&r1=903778&r2=903779&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
Wed Jan 27 18:29:07 2010
@@ -29,6 +29,7 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.Socket;
 import java.net.SocketAddress;
 import java.net.UnknownHostException;
 import java.nio.channels.CancelledKeyException;
@@ -59,6 +60,7 @@
  *  <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}</li>
  *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
  *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_REUSEADDR}</li>
  *  <li>{@link org.apache.http.nio.params.NIOReactorPNames#SELECT_INTERVAL}</li>
  *  <li>{@link org.apache.http.nio.params.NIOReactorPNames#GRACE_PERIOD}</li>
  *  <li>{@link org.apache.http.nio.params.NIOReactorPNames#INTEREST_OPS_QUEUEING}</li>
@@ -229,7 +231,9 @@
                 validateAddress(request.getRemoteAddress());
                 
                 if (request.getLocalAddress() != null) {
-                    socketChannel.socket().bind(request.getLocalAddress());
+                    Socket sock = socketChannel.socket();
+                    sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(this.params));
+                    sock.bind(request.getLocalAddress());
                 }
                 boolean connected = socketChannel.connect(request.getRemoteAddress());
                 if (connected) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/CoreConnectionPNames.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/CoreConnectionPNames.java?rev=903779&r1=903778&r2=903779&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/CoreConnectionPNames.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/CoreConnectionPNames.java
Wed Jan 27 18:29:07 2010
@@ -82,9 +82,24 @@
     public static final String SO_LINGER = "http.socket.linger"; 
 
     /**
+     * Defines whether the socket can be bound even though a previous connection is 
+     * still in a timeout state. 
+     * <p>
+     * This parameter expects a value of type {@link Boolean}.
+     * </p>
+     * @see java.net.Socket#setReuseAddress(boolean)
+     * 
+     * @since 4.1
+     */
+    public static final String SO_REUSEADDR = "http.socket.reuseaddr"; 
+
+    /**
      * Determines the timeout in milliseconds until a connection is established. 
      * A timeout value of zero is interpreted as an infinite timeout.
      * <p>
+     * Please note this parameter can only be applied to connections that 
+     * are bound to a particular local address.
+     * <p>
      * This parameter expects a value of type {@link Integer}.
      * </p>
      */

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpConnectionParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpConnectionParams.java?rev=903779&r1=903778&r2=903779&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpConnectionParams.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpConnectionParams.java
Wed Jan 27 18:29:07 2010
@@ -67,6 +67,37 @@
     }
 
     /**
+     * Obtains value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter.
+     * If not set, defaults to <code>false</code>.
+     *  
+     * @param params HTTP parameters.
+     * @return SO_REUSEADDR.
+     * 
+     * @since 4.1
+     */
+    public static boolean getSoReuseaddr(final HttpParams params) {
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        return params.getBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, false);
+    }
+
+    /**
+     * Sets value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter. 
+     *
+     * @param params HTTP parameters.
+     * @param reuseaddr SO_REUSEADDR.
+     * 
+     * @since 4.1
+     */
+    public static void setSoReuseaddr(final HttpParams params, boolean reuseaddr) {
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, reuseaddr);
+    }
+
+    /**
      * Obtains value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
      * If not set, defaults to <code>true</code>.
      *  



Mime
View raw message