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 2019/03/09 10:12:49 UTC
[httpcomponents-core] 01/01: Bug fix: non-blocking SSL I/O sessions
fail to fire session disconnected event
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
commit a3099a743d961db6b0e5c02f6043cd8dc3c7ad6a
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Mar 9 10:59:29 2019 +0100
Bug fix: non-blocking SSL I/O sessions fail to fire session disconnected event
---
.../hc/core5/reactor/InternalDataChannel.java | 10 ++++++
.../apache/hc/core5/reactor/ssl/SSLIOSession.java | 39 ++++++----------------
2 files changed, 21 insertions(+), 28 deletions(-)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
index a3de43f..4597e7d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
@@ -249,6 +249,16 @@ final class InternalDataChannel extends InternalChannel implements ProtocolIOSes
}
},
+ new Callback<SSLIOSession>() {
+
+ @Override
+ public void execute(final SSLIOSession sslSession) {
+ if (closed.compareAndSet(false, true)) {
+ closedSessions.add(InternalDataChannel.this);
+ }
+ }
+
+ },
handshakeTimeout))) {
throw new IllegalStateException("TLS already activated");
}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index f2d7493..145a318 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -81,7 +81,8 @@ public class SSLIOSession implements IOSession {
private final ByteChannel channel;
private final SSLSessionInitializer initializer;
private final SSLSessionVerifier verifier;
- private final Callback<SSLIOSession> callback;
+ private final Callback<SSLIOSession> connectedCallback;
+ private final Callback<SSLIOSession> disconnectedCallback;
private final AtomicLong bytesReadCount;
private int appEventMask;
@@ -94,29 +95,6 @@ public class SSLIOSession implements IOSession {
private TlsDetails tlsDetails;
/**
- * Creates new instance of {@code SSLIOSession} class with static SSL buffers.
- *
- * @param targetEndpoint target endpoint (applicable in client mode only). May be {@code null}.
- * @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 initializer optional SSL session initializer. May be {@code null}.
- * @param verifier optional SSL session verifier. May be {@code null}.
- *
- * @since 5.0
- */
- public SSLIOSession(
- final NamedEndpoint targetEndpoint,
- final IOSession session,
- final SSLMode sslMode,
- final SSLContext sslContext,
- final SSLSessionInitializer initializer,
- final SSLSessionVerifier verifier,
- final Callback<SSLIOSession> callback) {
- this(targetEndpoint, session, sslMode, sslContext, SSLBufferMode.STATIC, initializer, verifier, callback, null);
- }
-
- /**
* Creates new instance of {@code SSLIOSession} class.
*
* @param session I/O session to be decorated with the TLS/SSL capabilities.
@@ -138,7 +116,8 @@ public class SSLIOSession implements IOSession {
final SSLBufferMode sslBufferMode,
final SSLSessionInitializer initializer,
final SSLSessionVerifier verifier,
- final Callback<SSLIOSession> callback,
+ final Callback<SSLIOSession> connectedCallback,
+ final Callback<SSLIOSession> disconnectedCallback,
final Timeout connectTimeout) {
super();
Args.notNull(session, "IO session");
@@ -148,7 +127,8 @@ public class SSLIOSession implements IOSession {
this.sslMode = sslMode;
this.initializer = initializer;
this.verifier = verifier;
- this.callback = callback;
+ this.connectedCallback = connectedCallback;
+ this.disconnectedCallback = disconnectedCallback;
this.appEventMask = session.getEventMask();
if (this.sslMode == SSLMode.CLIENT && targetEndpoint != null) {
@@ -376,8 +356,8 @@ public class SSLIOSession implements IOSession {
final String applicationProtocol = ReflectionUtils.callGetter(this.sslEngine, "ApplicationProtocol", String.class);
this.tlsDetails = new TlsDetails(sslSession, applicationProtocol);
}
- if (this.callback != null) {
- this.callback.execute(this);
+ if (this.connectedCallback != null) {
+ this.connectedCallback.execute(this);
}
}
}
@@ -402,6 +382,9 @@ public class SSLIOSession implements IOSession {
}
if (this.status == CLOSED) {
this.session.close();
+ if (disconnectedCallback != null) {
+ disconnectedCallback.execute(this);
+ }
return;
}
// Need to toggle the event mask for this channel?