author | jbhateja |
Tue, 26 Nov 2019 16:09:25 +0300 | |
changeset 59278 | 8375560db76b |
parent 54811 | 9db7c0f561a6 |
permissions | -rw-r--r-- |
51642
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
1 |
/* |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
4 |
* |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
8 |
* |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
14 |
* |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
18 |
* |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
21 |
* questions. |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
22 |
*/ |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
23 |
|
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
24 |
/** |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
25 |
* @test |
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
51642
diff
changeset
|
26 |
* @library /test/lib |
51642
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
27 |
* @requires (os.family == "linux" | os.family == "mac" | os.family == "windows") |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
28 |
* @bug 8209152 |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
29 |
* @run main PrintSupportedOptions |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
30 |
* @run main/othervm -Djava.net.preferIPv4Stack=true PrintSupportedOptions |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
31 |
*/ |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
32 |
|
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
33 |
import java.io.IOException; |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
34 |
import java.net.SocketOption; |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
35 |
import java.nio.channels.*; |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
36 |
|
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
51642
diff
changeset
|
37 |
import jdk.test.lib.net.IPSupport; |
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
51642
diff
changeset
|
38 |
|
51642
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
39 |
public class PrintSupportedOptions { |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
40 |
|
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
41 |
@FunctionalInterface |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
42 |
interface NetworkChannelSupplier<T extends NetworkChannel> { |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
43 |
T get() throws IOException; |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
44 |
} |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
45 |
|
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
46 |
public static void main(String[] args) throws IOException { |
54811
9db7c0f561a6
8223652: Rename IPSupport.skipIfCurrentConfigurationIsInvalid() to IPSupport.throwSkippedExceptionIfNonOperational()
aeubanks
parents:
54770
diff
changeset
|
47 |
IPSupport.throwSkippedExceptionIfNonOperational(); |
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
51642
diff
changeset
|
48 |
|
51642
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
49 |
test(() -> SocketChannel.open()); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
50 |
test(() -> ServerSocketChannel.open()); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
51 |
test(() -> DatagramChannel.open()); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
52 |
|
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
53 |
test(() -> AsynchronousSocketChannel.open()); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
54 |
test(() -> AsynchronousServerSocketChannel.open()); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
55 |
} |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
56 |
|
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
57 |
@SuppressWarnings("unchecked") |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
58 |
static <T extends NetworkChannel> |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
59 |
void test(NetworkChannelSupplier<T> supplier) throws IOException { |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
60 |
try (T ch = supplier.get()) { |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
61 |
System.out.println(ch); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
62 |
for (SocketOption<?> opt : ch.supportedOptions()) { |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
63 |
Object value = ch.getOption(opt); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
64 |
System.out.format(" %s -> %s%n", opt.name(), value); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
65 |
if (value != null) { |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
66 |
ch.setOption((SocketOption<Object>) opt, value); |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
67 |
} |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
68 |
} |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
69 |
} |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
70 |
} |
d4099c45f148
8209152: (so) ServerSocketChannel::supportedOptions includes IP_TOS
alanb
parents:
diff
changeset
|
71 |
} |