1 /* |
1 /* |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package jdk.incubator.http.internal.common; |
26 package jdk.incubator.http.internal.common; |
27 |
27 |
28 import java.io.IOException; |
28 import jdk.incubator.http.internal.common.SubscriberWrapper.SchedulingAction; |
29 import java.lang.System.Logger.Level; |
29 |
30 import java.nio.ByteBuffer; |
|
31 import java.util.concurrent.Executor; |
|
32 import java.util.concurrent.Flow; |
|
33 import java.util.concurrent.Flow.Subscriber; |
|
34 import java.util.List; |
|
35 import java.util.ArrayList; |
|
36 import java.util.Collections; |
|
37 import java.util.Iterator; |
|
38 import java.util.LinkedList; |
|
39 import java.util.concurrent.CompletableFuture; |
|
40 import java.util.concurrent.ConcurrentLinkedQueue; |
|
41 import java.util.concurrent.atomic.AtomicInteger; |
|
42 import javax.net.ssl.SSLEngine; |
30 import javax.net.ssl.SSLEngine; |
43 import javax.net.ssl.SSLEngineResult; |
31 import javax.net.ssl.SSLEngineResult; |
44 import javax.net.ssl.SSLEngineResult.HandshakeStatus; |
32 import javax.net.ssl.SSLEngineResult.HandshakeStatus; |
45 import javax.net.ssl.SSLEngineResult.Status; |
33 import javax.net.ssl.SSLEngineResult.Status; |
46 import javax.net.ssl.SSLException; |
34 import javax.net.ssl.SSLException; |
47 import jdk.incubator.http.internal.common.SubscriberWrapper.SchedulingAction; |
35 import java.io.IOException; |
|
36 import java.lang.System.Logger.Level; |
|
37 import java.nio.ByteBuffer; |
|
38 import java.util.ArrayList; |
|
39 import java.util.Collections; |
|
40 import java.util.Iterator; |
|
41 import java.util.LinkedList; |
|
42 import java.util.List; |
|
43 import java.util.concurrent.CompletableFuture; |
|
44 import java.util.concurrent.ConcurrentLinkedQueue; |
|
45 import java.util.concurrent.Executor; |
|
46 import java.util.concurrent.Flow; |
|
47 import java.util.concurrent.Flow.Subscriber; |
|
48 import java.util.concurrent.atomic.AtomicInteger; |
48 |
49 |
49 /** |
50 /** |
50 * Implements SSL using two SubscriberWrappers. |
51 * Implements SSL using two SubscriberWrappers. |
51 * |
52 * |
52 * <p> Constructor takes two Flow.Subscribers: one that receives the network |
53 * <p> Constructor takes two Flow.Subscribers: one that receives the network |
87 final Executor exec; |
88 final Executor exec; |
88 final Reader reader; |
89 final Reader reader; |
89 final Writer writer; |
90 final Writer writer; |
90 final SSLEngine engine; |
91 final SSLEngine engine; |
91 final String tubeName; // hack |
92 final String tubeName; // hack |
92 final CompletableFuture<Void> cf; |
93 private final CompletableFuture<Void> cf; |
93 final CompletableFuture<String> alpnCF; // completes on initial handshake |
94 final CompletableFuture<String> alpnCF; // completes on initial handshake |
94 final static ByteBuffer SENTINEL = Utils.EMPTY_BYTEBUFFER; |
95 final static ByteBuffer SENTINEL = Utils.EMPTY_BYTEBUFFER; |
95 volatile boolean close_notify_received; |
96 volatile boolean close_notify_received; |
96 |
97 |
97 /** |
98 /** |
108 this.reader = new Reader(); |
109 this.reader = new Reader(); |
109 this.writer = new Writer(); |
110 this.writer = new Writer(); |
110 this.engine = engine; |
111 this.engine = engine; |
111 this.exec = exec; |
112 this.exec = exec; |
112 this.handshakeState = new AtomicInteger(NOT_HANDSHAKING); |
113 this.handshakeState = new AtomicInteger(NOT_HANDSHAKING); |
113 this.cf = CompletableFuture.allOf(reader.completion(), writer.completion()) |
114 CompletableFuture<Void> cs = CompletableFuture.allOf( |
114 .thenRun(this::normalStop); |
115 reader.completion(), writer.completion()).thenRun(this::normalStop); |
|
116 this.cf = MinimalFuture.of(cs); |
115 this.alpnCF = new MinimalFuture<>(); |
117 this.alpnCF = new MinimalFuture<>(); |
116 |
118 |
117 // connect the Reader to the downReader and the |
119 // connect the Reader to the downReader and the |
118 // Writer to the downWriter. |
120 // Writer to the downWriter. |
119 connect(downReader, downWriter); |
121 connect(downReader, downWriter); |