hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-core git commit: HTTPCORE-488: SingleCoreIOReactor#connect timeout parameter has no effect
Date Wed, 06 Sep 2017 12:52:52 GMT
Repository: httpcomponents-core
Updated Branches:
  refs/heads/master b95783f4e -> 6e22c52f6


HTTPCORE-488: SingleCoreIOReactor#connect timeout parameter has no effect


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/6e22c52f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/6e22c52f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/6e22c52f

Branch: refs/heads/master
Commit: 6e22c52f689597741503ce2a85881b249f4728f4
Parents: b95783f
Author: xiaohu-zhang <silver9886@126.com>
Authored: Wed Sep 6 14:03:50 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Wed Sep 6 14:08:00 2017 +0200

----------------------------------------------------------------------
 .../hc/core5/reactor/InternalChannel.java       |  4 +++-
 .../core5/reactor/InternalConnectChannel.java   | 22 ++++++++++++--------
 2 files changed, 16 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/6e22c52f/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
index 47b6d6d..525eb45 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
@@ -61,7 +61,7 @@ abstract class InternalChannel implements GracefullyCloseable {
         }
     }
 
-    final void checkTimeout(final long currentTime) {
+    final boolean checkTimeout(final long currentTime) {
         final int timeout = getTimeout();
         if (timeout > 0) {
             final long deadline = lastEventTime + timeout;
@@ -74,8 +74,10 @@ abstract class InternalChannel implements GracefullyCloseable {
                     onException(ex);
                     shutdown(ShutdownType.IMMEDIATE);
                 }
+                return false;
             }
         }
+        return true;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/6e22c52f/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
index ee2d5f6..8f1cbab 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
@@ -59,14 +59,18 @@ final class InternalConnectChannel extends InternalChannel {
             if (socketChannel.isConnectionPending()) {
                 socketChannel.finishConnect();
             }
-            final InternalDataChannel dataChannel = dataChannelFactory.create(
-                    key,
-                    socketChannel,
-                    sessionRequest.remoteEndpoint,
-                    sessionRequest.attachment);
-            key.attach(dataChannel);
-            sessionRequest.completed(dataChannel);
-            dataChannel.handleIOEvent(SelectionKey.OP_CONNECT);
+            //check out connectTimeout
+            final long now = System.currentTimeMillis();
+            if (checkTimeout(now)) {
+                final InternalDataChannel dataChannel = dataChannelFactory.create(
+                        key,
+                        socketChannel,
+                        sessionRequest.remoteEndpoint,
+                        sessionRequest.attachment);
+                key.attach(dataChannel);
+                sessionRequest.completed(dataChannel);
+                dataChannel.handleIOEvent(SelectionKey.OP_CONNECT);
+            }
         }
     }
 
@@ -78,6 +82,7 @@ final class InternalConnectChannel extends InternalChannel {
     @Override
     void onTimeout() throws IOException {
         sessionRequest.failed(new SocketTimeoutException());
+        close();
     }
 
     @Override
@@ -98,5 +103,4 @@ final class InternalConnectChannel extends InternalChannel {
         } catch (final IOException ignore) {
         }
     }
-
 }


Mime
View raw message