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/01/24 12:49:01 UTC

svn commit: r1560947 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http: impl/nio/reactor/ nio/reactor/ssl/

Author: olegk
Date: Fri Jan 24 11:49:01 2014
New Revision: 1560947

URL: http://svn.apache.org/r1560947
Log:
Merge remote-tracking branch 'github/trunk' into trunk

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java?rev=1560947&r1=1560946&r2=1560947&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java Fri Jan 24 11:49:01 2014
@@ -242,7 +242,7 @@ public class DefaultListeningIOReactor e
                     socket.setReceiveBufferSize(this.config.getRcvBufSize());
                 }
                 serverChannel.configureBlocking(false);
-                socket.bind(address);
+                socket.bind(address, this.config.getBacklogSize());
             } catch (final IOException ex) {
                 closeChannel(serverChannel);
                 request.failed(ex);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java?rev=1560947&r1=1560946&r2=1560947&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java Fri Jan 24 11:49:01 2014
@@ -55,6 +55,7 @@ public final class IOReactorConfig imple
     private int connectTimeout;
     private int sndBufSize;
     private int rcvBufSize;
+    private int backlogSize;
 
     @Deprecated
     public IOReactorConfig() {
@@ -71,6 +72,7 @@ public final class IOReactorConfig imple
         this.connectTimeout = 0;
         this.sndBufSize = 0;
         this.rcvBufSize = 0;
+        this.backlogSize = 0;
     }
 
     IOReactorConfig(
@@ -85,7 +87,8 @@ public final class IOReactorConfig imple
             final boolean tcpNoDelay,
             final int connectTimeout,
             final int sndBufSize,
-            final int rcvBufSize) {
+            final int rcvBufSize,
+            final int backlogSize) {
         super();
         this.selectInterval = selectInterval;
         this.shutdownGracePeriod = shutdownGracePeriod;
@@ -99,6 +102,7 @@ public final class IOReactorConfig imple
         this.connectTimeout = connectTimeout;
         this.sndBufSize = sndBufSize;
         this.rcvBufSize = rcvBufSize;
+        this.backlogSize = backlogSize;
     }
 
     /**
@@ -336,6 +340,17 @@ public final class IOReactorConfig imple
         this.rcvBufSize = rcvBufSize;
     }
 
+    /**
+     * Determines the default backlog size value for server sockets binds.
+     * <p/>
+     * Default: <code>0</code> (system default)
+     *
+     * @since 4.4
+     */
+    public int getBacklogSize() {
+        return backlogSize;
+    }
+
     @Override
     protected IOReactorConfig clone() throws CloneNotSupportedException {
         return (IOReactorConfig) super.clone();
@@ -357,7 +372,10 @@ public final class IOReactorConfig imple
             .setSoLinger(config.getSoLinger())
             .setSoKeepAlive(config.isSoKeepalive())
             .setTcpNoDelay(config.isTcpNoDelay())
-            .setConnectTimeout(config.getConnectTimeout());
+            .setConnectTimeout(config.getConnectTimeout())
+            .setSndBufSize(config.getSndBufSize())
+            .setRcvBufSize(config.getRcvBufSize())
+            .setBacklogSize(config.getBacklogSize());
     }
 
     public static class Builder {
@@ -374,6 +392,7 @@ public final class IOReactorConfig imple
         private int connectTimeout;
         private int sndBufSize;
         private int rcvBufSize;
+        private int backlogSize;
 
         Builder() {
             this.selectInterval = 1000;
@@ -388,6 +407,7 @@ public final class IOReactorConfig imple
             this.connectTimeout = 0;
             this.sndBufSize = 0;
             this.rcvBufSize = 0;
+            this.backlogSize = 0;
         }
 
         public Builder setSelectInterval(final long selectInterval) {
@@ -450,11 +470,16 @@ public final class IOReactorConfig imple
             return this;
         }
 
+        public Builder setBacklogSize(final int backlogSize) {
+            this.backlogSize = backlogSize;
+            return this;
+        }
+
         public IOReactorConfig build() {
             return new IOReactorConfig(
                     selectInterval, shutdownGracePeriod, interestOpQueued, ioThreadCount,
                     soTimeout, soReuseAddress, soLinger, soKeepAlive, tcpNoDelay,
-                    connectTimeout, sndBufSize, rcvBufSize);
+                    connectTimeout, sndBufSize, rcvBufSize, backlogSize);
         }
 
     }
@@ -474,6 +499,7 @@ public final class IOReactorConfig imple
                 .append(", connectTimeout=").append(this.connectTimeout)
                 .append(", sndBufSize=").append(this.sndBufSize)
                 .append(", rcvBufSize=").append(this.rcvBufSize)
+                .append(", backlogSize=").append(this.backlogSize)
                 .append("]");
         return builder.toString();
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java?rev=1560947&r1=1560946&r2=1560947&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java Fri Jan 24 11:49:01 2014
@@ -143,11 +143,9 @@ public class ListenerEndpointImpl implem
         if (this.key != null) {
             this.key.cancel();
             final Channel channel = this.key.channel();
-            if (channel.isOpen()) {
-                try {
-                    channel.close();
-                } catch (final IOException ignore) {}
-            }
+            try {
+                channel.close();
+            } catch (final IOException ignore) {}
         }
         if (this.callback != null) {
             this.callback.endpointClosed(this);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java?rev=1560947&r1=1560946&r2=1560947&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java Fri Jan 24 11:49:01 2014
@@ -149,11 +149,9 @@ public class SessionRequestImpl implemen
         if (key != null) {
             key.cancel();
             final Channel channel = key.channel();
-            if (channel.isOpen()) {
-                try {
-                    channel.close();
-                } catch (final IOException ignore) {}
-            }
+            try {
+                channel.close();
+            } catch (final IOException ignore) {}
         }
         synchronized (this) {
             this.exception = exception;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java?rev=1560947&r1=1560946&r2=1560947&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java Fri Jan 24 11:49:01 2014
@@ -28,7 +28,6 @@
 package org.apache.http.nio.reactor.ssl;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
 import java.nio.ByteBuffer;
@@ -43,6 +42,7 @@ import javax.net.ssl.SSLEngineResult.Sta
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLSession;
 
+import org.apache.http.HttpHost;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
@@ -99,12 +99,16 @@ public class SSLIOSession implements IOS
      *
      * @param session I/O session to be decorated with the TLS/SSL capabilities.
      * @param sslMode SSL mode (client or server)
+     * @param host original host (applicable in client mode only)
      * @param sslContext SSL context to use for this I/O session.
      * @param handler optional SSL setup handler. May be <code>null</code>.
+     *
+     * @since 4.4
      */
     public SSLIOSession(
             final IOSession session,
             final SSLMode sslMode,
+            final HttpHost host,
             final SSLContext sslContext,
             final SSLSetupHandler handler) {
         super();
@@ -119,15 +123,8 @@ public class SSLIOSession implements IOS
         // Override the status buffer interface
         this.session.setBufferStatus(this);
 
-        if (this.sslMode == SSLMode.CLIENT) {
-            final SocketAddress address = session.getRemoteAddress();
-            if (address instanceof InetSocketAddress) {
-                final String hostname = ((InetSocketAddress) address).getHostName();
-                final int port = ((InetSocketAddress) address).getPort();
-                this.sslEngine = sslContext.createSSLEngine(hostname, port);
-            } else {
-                this.sslEngine = sslContext.createSSLEngine();
-            }
+        if (this.sslMode == SSLMode.CLIENT && host != null) {
+            this.sslEngine = sslContext.createSSLEngine(host.getHostName(), host.getPort());
         } else {
             this.sslEngine = sslContext.createSSLEngine();
         }
@@ -143,6 +140,22 @@ public class SSLIOSession implements IOS
         this.outPlain = ByteBuffer.allocate(appBuffersize);
     }
 
+    /**
+     * Creates new instance of <tt>SSLIOSession</tt> class.
+     *
+     * @param session I/O session to be decorated with the TLS/SSL capabilities.
+     * @param sslMode SSL mode (client or server)
+     * @param sslContext SSL context to use for this I/O session.
+     * @param handler optional SSL setup handler. May be <code>null</code>.
+     */
+    public SSLIOSession(
+            final IOSession session,
+            final SSLMode sslMode,
+            final SSLContext sslContext,
+            final SSLSetupHandler handler) {
+        this(session, sslMode, null, sslContext, handler);
+    }
+
     protected SSLSetupHandler getSSLSetupHandler() {
         return this.handler;
     }