Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/Socket/TrafficClass.java
41149 views
1
/*
2
* Copyright (c) 2001, 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
* @test
26
* @bug 4511783
27
* @library /test/lib
28
* @summary Test that setTrafficClass/getTraffiClass don't
29
* throw an exception
30
* @run main TrafficClass
31
* @run main/othervm -Djava.net.preferIPv4Stack=true TrafficClass
32
*/
33
import java.net.*;
34
import java.nio.*;
35
import java.nio.channels.*;
36
import jdk.test.lib.net.IPSupport;
37
38
public class TrafficClass {
39
40
static final int IPTOS_RELIABILITY = 0x4;
41
42
static int failures = 0;
43
44
static void testDatagramSocket(DatagramSocket s) {
45
try {
46
s.setTrafficClass( IPTOS_RELIABILITY );
47
int tc = s.getTrafficClass();
48
} catch (Exception e) {
49
failures++;
50
System.err.println("testDatagramSocket failed: " + e);
51
}
52
}
53
54
static void testSocket(Socket s) {
55
try {
56
s.setTrafficClass(IPTOS_RELIABILITY);
57
int tc = s.getTrafficClass();
58
} catch (Exception e) {
59
failures++;
60
System.err.println("testSocket failed: " + e);
61
}
62
63
}
64
65
public static void main(String args[]) throws Exception {
66
IPSupport.throwSkippedExceptionIfNonOperational();
67
68
DatagramSocket ds = new DatagramSocket();
69
testDatagramSocket(ds);
70
71
DatagramChannel dc = DatagramChannel.open();
72
testDatagramSocket(dc.socket());
73
74
Socket s = new Socket();
75
testSocket(s);
76
77
SocketChannel sc = SocketChannel.open();
78
testSocket(sc.socket());
79
80
if (failures > 0) {
81
throw new Exception(failures + " sub-test(s) failed - " +
82
"see log for details.");
83
}
84
}
85
86
}
87
88