Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLSocketImpl/BlockedAsyncClose.java
41152 views
1
/*
2
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
//
25
// SunJSSE does not support dynamic system properties, no way to re-use
26
// system properties in samevm/agentvm mode.
27
//
28
29
/*
30
* @test
31
* @bug 8224829
32
* @summary AsyncSSLSocketClose.java has timing issue
33
* @run main/othervm BlockedAsyncClose
34
*/
35
36
import javax.net.ssl.*;
37
import java.io.*;
38
import java.net.SocketException;
39
import java.net.InetAddress;
40
import java.net.InetSocketAddress;
41
import java.util.concurrent.CountDownLatch;
42
import java.util.concurrent.TimeUnit;
43
44
public class BlockedAsyncClose implements Runnable {
45
SSLSocket socket;
46
SSLServerSocket ss;
47
48
// Is the socket ready to close?
49
private final CountDownLatch closeCondition = new CountDownLatch(1);
50
51
// Where do we find the keystores?
52
static String pathToStores = "../../../../javax/net/ssl/etc";
53
static String keyStoreFile = "keystore";
54
static String trustStoreFile = "truststore";
55
static String passwd = "passphrase";
56
57
public static void main(String[] args) throws Exception {
58
String keyFilename =
59
System.getProperty("test.src", "./") + "/" + pathToStores +
60
"/" + keyStoreFile;
61
String trustFilename =
62
System.getProperty("test.src", "./") + "/" + pathToStores +
63
"/" + trustStoreFile;
64
65
System.setProperty("javax.net.ssl.keyStore", keyFilename);
66
System.setProperty("javax.net.ssl.keyStorePassword", passwd);
67
System.setProperty("javax.net.ssl.trustStore", trustFilename);
68
System.setProperty("javax.net.ssl.trustStorePassword", passwd);
69
70
new BlockedAsyncClose();
71
}
72
73
public BlockedAsyncClose() throws Exception {
74
SSLServerSocketFactory sslssf =
75
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
76
InetAddress loopback = InetAddress.getLoopbackAddress();
77
ss = (SSLServerSocket)sslssf.createServerSocket();
78
ss.bind(new InetSocketAddress(loopback, 0));
79
80
SSLSocketFactory sslsf =
81
(SSLSocketFactory)SSLSocketFactory.getDefault();
82
socket = (SSLSocket)sslsf.createSocket(loopback, ss.getLocalPort());
83
SSLSocket serverSoc = (SSLSocket)ss.accept();
84
ss.close();
85
86
(new Thread(this)).start();
87
serverSoc.startHandshake();
88
89
boolean closeIsReady = closeCondition.await(90L, TimeUnit.SECONDS);
90
if (!closeIsReady) {
91
System.out.println(
92
"Ignore, the closure is not ready yet in 90 seconds.");
93
return;
94
}
95
96
socket.setSoLinger(true, 10);
97
System.out.println("Calling Socket.close");
98
99
// Sleep for a while so that the write thread blocks by hitting the
100
// output stream buffer limit.
101
Thread.sleep(1000);
102
103
socket.close();
104
System.out.println("ssl socket get closed");
105
System.out.flush();
106
}
107
108
// block in write
109
public void run() {
110
byte[] ba = new byte[1024];
111
for (int i = 0; i < ba.length; i++) {
112
ba[i] = 0x7A;
113
}
114
115
try {
116
OutputStream os = socket.getOutputStream();
117
int count = 0;
118
119
// 1st round write
120
count += ba.length;
121
System.out.println(count + " bytes to be written");
122
os.write(ba);
123
System.out.println(count + " bytes written");
124
125
// Signal, ready to close.
126
closeCondition.countDown();
127
128
// write more
129
while (true) {
130
count += ba.length;
131
System.out.println(count + " bytes to be written");
132
os.write(ba);
133
System.out.println(count + " bytes written");
134
}
135
} catch (SocketException se) {
136
// the closing may be in progress
137
System.out.println("interrupted? " + se);
138
} catch (Exception e) {
139
if (socket.isClosed() || socket.isOutputShutdown()) {
140
System.out.println("interrupted, the socket is closed");
141
} else {
142
throw new RuntimeException("interrupted?", e);
143
}
144
}
145
}
146
}
147
148
149