Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/Socket/RST.java
41149 views
1
/*
2
* Copyright (c) 2001, 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
* @test
26
* @bug 4468997
27
* @library /test/lib
28
* @summary SO_LINGER is ignored on Windows with Winsock 2
29
* @run main RST
30
* @run main/othervm -Djava.net.preferIPv4Stack=true RST
31
*/
32
import java.net.*;
33
import java.io.*;
34
import jdk.test.lib.net.IPSupport;
35
36
public class RST implements Runnable {
37
38
Socket client;
39
40
public void run() {
41
try {
42
client.setSoLinger(true, 0); // hard reset
43
client.close();
44
} catch (Exception e) {
45
e.printStackTrace();
46
}
47
}
48
49
RST() throws Exception {
50
InetAddress loopback = InetAddress.getLoopbackAddress();
51
ServerSocket ss = new ServerSocket();
52
ss.bind(new InetSocketAddress(loopback, 0));
53
client = new Socket(loopback, ss.getLocalPort());
54
Socket server = ss.accept();
55
56
Thread thr = new Thread(this);
57
thr.start();
58
59
SocketException exc = null;
60
try {
61
InputStream in = server.getInputStream();
62
63
/*
64
* This read should throw a SocketException indicating a
65
* connection reset.
66
*/
67
int n = in.read();
68
} catch (SocketException se) {
69
exc = se;
70
}
71
72
server.close();
73
ss.close();
74
75
if (exc == null) {
76
throw new Exception("Expected SocketException not thrown");
77
}
78
if (exc.getMessage().toLowerCase().indexOf("reset") == -1) {
79
throw new Exception("SocketException thrown but not expected \"connection reset\"");
80
}
81
}
82
83
84
public static void main(String args[]) throws Exception {
85
IPSupport.throwSkippedExceptionIfNonOperational();
86
87
new RST();
88
}
89
}
90
91