Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLSocketImpl/AsyncSSLSocketClose.java
41152 views
1
/*
2
* Copyright (c) 2007, 2018, 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 6447412
32
* @summary Issue with socket.close() for ssl sockets when poweroff on
33
* other system
34
* @run main/othervm AsyncSSLSocketClose
35
*/
36
37
import javax.net.ssl.*;
38
import java.io.*;
39
import java.net.SocketException;
40
import java.util.concurrent.CountDownLatch;
41
import java.util.concurrent.TimeUnit;
42
43
public class AsyncSSLSocketClose implements Runnable {
44
SSLSocket socket;
45
SSLServerSocket ss;
46
47
// Is the socket ready to close?
48
private final CountDownLatch closeCondition = new CountDownLatch(1);
49
50
// Where do we find the keystores?
51
static String pathToStores = "../../../../javax/net/ssl/etc";
52
static String keyStoreFile = "keystore";
53
static String trustStoreFile = "truststore";
54
static String passwd = "passphrase";
55
56
public static void main(String[] args) throws Exception {
57
String keyFilename =
58
System.getProperty("test.src", "./") + "/" + pathToStores +
59
"/" + keyStoreFile;
60
String trustFilename =
61
System.getProperty("test.src", "./") + "/" + pathToStores +
62
"/" + trustStoreFile;
63
64
System.setProperty("javax.net.ssl.keyStore", keyFilename);
65
System.setProperty("javax.net.ssl.keyStorePassword", passwd);
66
System.setProperty("javax.net.ssl.trustStore", trustFilename);
67
System.setProperty("javax.net.ssl.trustStorePassword", passwd);
68
69
new AsyncSSLSocketClose();
70
}
71
72
public AsyncSSLSocketClose() throws Exception {
73
SSLServerSocketFactory sslssf =
74
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
75
ss = (SSLServerSocket) sslssf.createServerSocket(0);
76
77
SSLSocketFactory sslsf =
78
(SSLSocketFactory)SSLSocketFactory.getDefault();
79
socket = (SSLSocket)sslsf.createSocket("localhost", ss.getLocalPort());
80
SSLSocket serverSoc = (SSLSocket)ss.accept();
81
ss.close();
82
83
(new Thread(this)).start();
84
serverSoc.startHandshake();
85
86
boolean closeIsReady = closeCondition.await(90L, TimeUnit.SECONDS);
87
if (!closeIsReady) {
88
System.out.println(
89
"Ignore, the closure is not ready yet in 90 seconds.");
90
return;
91
}
92
93
socket.setSoLinger(true, 10);
94
System.out.println("Calling Socket.close");
95
socket.close();
96
System.out.println("ssl socket get closed");
97
System.out.flush();
98
}
99
100
// block in write
101
public void run() {
102
byte[] ba = new byte[1024];
103
for (int i = 0; i < ba.length; i++) {
104
ba[i] = 0x7A;
105
}
106
107
try {
108
OutputStream os = socket.getOutputStream();
109
int count = 0;
110
111
// 1st round write
112
count += ba.length;
113
System.out.println(count + " bytes to be written");
114
os.write(ba);
115
System.out.println(count + " bytes written");
116
117
// Signal, ready to close.
118
closeCondition.countDown();
119
120
// write more
121
while (true) {
122
count += ba.length;
123
System.out.println(count + " bytes to be written");
124
os.write(ba);
125
System.out.println(count + " bytes written");
126
}
127
} catch (SocketException se) {
128
// the closing may be in progress
129
System.out.println("interrupted? " + se);
130
} catch (Exception e) {
131
if (socket.isClosed() || socket.isOutputShutdown()) {
132
System.out.println("interrupted, the socket is closed");
133
} else {
134
throw new RuntimeException("interrupted?", e);
135
}
136
}
137
}
138
}
139
140
141