Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/Socket/SetSoLinger.java
41149 views
1
/*
2
* Copyright (c) 1998, 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 4151834
27
* @library /test/lib
28
* @summary Test Socket.setSoLinger
29
* @run main SetSoLinger
30
* @run main/othervm -Djava.net.preferIPv4Stack=true SetSoLinger
31
* @run main/othervm -Djava.net.preferIPv6Addresses=true SetSoLinger
32
*/
33
34
import java.net.*;
35
import jdk.test.lib.net.IPSupport;
36
37
public class SetSoLinger {
38
static final int LINGER = 65546;
39
40
public static void main(String args[]) throws Exception {
41
IPSupport.throwSkippedExceptionIfNonOperational();
42
43
int value;
44
InetAddress addr = InetAddress.getLocalHost();
45
ServerSocket ss = new ServerSocket();
46
47
InetSocketAddress socketAddress = new InetSocketAddress(addr, 0);
48
ss.bind(socketAddress);
49
int port = ss.getLocalPort();
50
51
Socket s = new Socket(addr, port);
52
Socket soc = ss.accept();
53
soc.setSoLinger(true, LINGER);
54
value = soc.getSoLinger();
55
soc.close();
56
s.close();
57
ss.close();
58
59
if(value != 65535)
60
throw new RuntimeException("Failed. Value not properly reduced.");
61
}
62
}
63
64