author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 55226 | ce8bab2c4185 |
child 58679 | 9c3209ff7550 |
child 59206 | 61091a42f19d |
permissions | -rw-r--r-- |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
1 |
/* |
54086
ccb4a50bee06
8220083: Use InetAddress.getLoopbackAddress() in place of 127.0.0.1 for some tests
aeubanks
parents:
48397
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
4 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
8 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
14 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
18 |
* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
21 |
* questions. |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
22 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
23 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
24 |
/* |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
25 |
* @test |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
26 |
* @bug 8036979 8072384 8044773 8225214 |
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
54681
diff
changeset
|
27 |
* @library /test/lib |
48397
ead47ddf5844
8191788: add jdk.internal.vm.compiler to --limit-modules if -Djvmci.Compiler=graal is in the command line
kvn
parents:
47216
diff
changeset
|
28 |
* @requires !vm.graal.enabled |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
29 |
* @run main/othervm -Xcheck:jni OptionsTest |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
30 |
* @run main/othervm -Djdk.net.usePlainSocketImpl OptionsTest |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
23879
diff
changeset
|
31 |
* @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true OptionsTest |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38474
diff
changeset
|
32 |
* @run main/othervm --limit-modules=java.base OptionsTest |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
33 |
*/ |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
34 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
35 |
import java.lang.reflect.Method; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
36 |
import java.net.*; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
37 |
import java.util.*; |
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
54681
diff
changeset
|
38 |
import jdk.test.lib.net.IPSupport; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
39 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
40 |
public class OptionsTest { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
41 |
|
55102 | 42 |
static class Test<T> { |
43 |
final SocketOption<T> option; |
|
44 |
final T value; |
|
45 |
Test(SocketOption<T> option, T value) { |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
46 |
this.option = option; |
55102 | 47 |
this.value = value; |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
48 |
} |
55102 | 49 |
static <T> Test<T> create(SocketOption<T> option, T value) { |
50 |
return new Test<T>(option, value); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
51 |
} |
55102 | 52 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
53 |
} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
54 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
55 |
// The tests set the option using the new API, read back the set value |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
56 |
// which could be different, and then use the legacy get API to check |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
57 |
// these values are the same |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
58 |
|
55102 | 59 |
static Test<?>[] socketTests = new Test<?>[] { |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
60 |
Test.create(StandardSocketOptions.SO_KEEPALIVE, Boolean.TRUE), |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
61 |
Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)), |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
62 |
Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
63 |
Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), |
36115 | 64 |
Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
65 |
Test.create(StandardSocketOptions.SO_LINGER, Integer.valueOf(-1)), |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
66 |
Test.create(StandardSocketOptions.SO_LINGER, Integer.valueOf(0)), |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
67 |
Test.create(StandardSocketOptions.SO_LINGER, Integer.valueOf(80)), |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
68 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(0)), // lower-bound |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
69 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)), |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
70 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(255)) //upper-bound |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
71 |
}; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
72 |
|
55102 | 73 |
static Test<?>[] serverSocketTests = new Test<?>[] { |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
74 |
Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), |
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
23879
diff
changeset
|
75 |
Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), |
36115 | 76 |
Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
77 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(0)), // lower-bound |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
78 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)), |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
79 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(255)) //upper-bound |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
80 |
}; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
81 |
|
55102 | 82 |
static Test<?>[] datagramSocketTests = new Test<?>[] { |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
83 |
Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)), |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
84 |
Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
85 |
Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), |
36115 | 86 |
Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
87 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(0)), // lower-bound |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
88 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)), |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
89 |
Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(255)) //upper-bound |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
90 |
}; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
91 |
|
55102 | 92 |
static Test<?>[] multicastSocketTests = new Test<?>[] { |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
93 |
Test.create(StandardSocketOptions.IP_MULTICAST_IF, getNetworkInterface()), |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
94 |
Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(0)), // lower-bound |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
95 |
Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(10)), |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54811
diff
changeset
|
96 |
Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(255)), //upper-bound |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
97 |
Test.create(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.TRUE) |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
98 |
}; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
99 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
100 |
static NetworkInterface getNetworkInterface() { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
101 |
try { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
102 |
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); |
34889
9aac81c72779
8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents:
30963
diff
changeset
|
103 |
while (nifs.hasMoreElements()) { |
55102 | 104 |
NetworkInterface ni = nifs.nextElement(); |
34889
9aac81c72779
8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents:
30963
diff
changeset
|
105 |
if (ni.supportsMulticast()) { |
9aac81c72779
8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents:
30963
diff
changeset
|
106 |
return ni; |
9aac81c72779
8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents:
30963
diff
changeset
|
107 |
} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
108 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
109 |
} catch (Exception e) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
110 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
111 |
return null; |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
112 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
113 |
|
55102 | 114 |
static boolean okayToTest(Socket s, SocketOption<?> option) { |
115 |
if (option == StandardSocketOptions.SO_REUSEPORT) { |
|
116 |
// skip SO_REUSEPORT if option is not supported |
|
117 |
return s.supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT); |
|
118 |
} |
|
119 |
if (option == StandardSocketOptions.IP_TOS && s.isConnected()) { |
|
120 |
// skip IP_TOS if connected |
|
121 |
return false; |
|
122 |
} |
|
123 |
return true; |
|
124 |
} |
|
125 |
||
126 |
static <T> void testEqual(SocketOption<T> option, T value1, T value2) { |
|
127 |
if (!value1.equals(value2)) { |
|
128 |
throw new RuntimeException("Test of " + option.name() + " failed: " |
|
129 |
+ value1 + " != " + value2); |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
static <T> void test(Socket s, Test<T> test) throws Exception { |
|
134 |
SocketOption<T> option = test.option; |
|
135 |
s.setOption(option, test.value); |
|
136 |
T value1 = s.getOption(test.option); |
|
137 |
T value2 = (T) legacyGetOption(Socket.class, s, test.option); |
|
138 |
testEqual(option, value1, value2); |
|
139 |
} |
|
140 |
||
141 |
static <T> void test(ServerSocket ss, Test<T> test) throws Exception { |
|
142 |
SocketOption<T> option = test.option; |
|
143 |
ss.setOption(option, test.value); |
|
144 |
T value1 = ss.getOption(test.option); |
|
145 |
T value2 = (T) legacyGetOption(ServerSocket.class, ss, test.option); |
|
146 |
testEqual(option, value1, value2); |
|
147 |
} |
|
148 |
||
149 |
static <T> void test(DatagramSocket ds, Test<T> test) throws Exception { |
|
150 |
SocketOption<T> option = test.option; |
|
151 |
ds.setOption(option, test.value); |
|
152 |
T value1 = ds.getOption(test.option); |
|
153 |
T value2 = (T) legacyGetOption(ds.getClass(), ds, test.option); |
|
154 |
testEqual(option, value1, value2); |
|
155 |
} |
|
156 |
||
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
157 |
// Tests default and negative values of SO_LINGER. All negative values should |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
158 |
// retrieve as -1. |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
159 |
static void testSoLingerValues() throws Exception { |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
160 |
try (Socket s = new Socket()) { |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
161 |
// retrieve without set |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
162 |
int defaultValue = s.getOption(StandardSocketOptions.SO_LINGER); |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
163 |
testEqual(StandardSocketOptions.SO_LINGER, -1, defaultValue); |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
164 |
|
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
165 |
for (int v : List.of(-1, -2, -100, -65534, -65535, -65536, -100000)) { |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
166 |
System.out.println("Testing SO_LINGER with:" + v); |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
167 |
s.setOption(StandardSocketOptions.SO_LINGER, v); |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
168 |
int value = s.getOption(StandardSocketOptions.SO_LINGER); |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
169 |
testEqual(StandardSocketOptions.SO_LINGER, -1, value); |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
170 |
} |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
171 |
} |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
172 |
} |
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
173 |
|
55102 | 174 |
@SuppressWarnings("try") |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
175 |
static void doSocketTests() throws Exception { |
55102 | 176 |
// unconnected socket |
177 |
try (Socket s = new Socket()) { |
|
178 |
for (Test<?> test : socketTests) { |
|
179 |
if (okayToTest(s, test.option)) { |
|
180 |
test(s, test); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
181 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
182 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
183 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
184 |
|
55102 | 185 |
// connected socket |
186 |
try (ServerSocket ss = new ServerSocket()) { |
|
187 |
var loopback = InetAddress.getLoopbackAddress(); |
|
188 |
ss.bind(new InetSocketAddress(loopback, 0)); |
|
189 |
try (Socket s1 = new Socket()) { |
|
190 |
s1.connect(ss.getLocalSocketAddress()); |
|
191 |
try (Socket s2 = ss.accept()) { |
|
192 |
for (Test<?> test : socketTests) { |
|
193 |
if (okayToTest(s1, test.option)) { |
|
194 |
test(s1, test); |
|
195 |
} |
|
36115 | 196 |
} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
197 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
198 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
199 |
} |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
200 |
|
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
201 |
testSoLingerValues(); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
202 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
203 |
|
55102 | 204 |
static void doServerSocketTests() throws Exception { |
205 |
try (ServerSocket ss = new ServerSocket(0)) { |
|
206 |
Set<SocketOption<?>> options = ss.supportedOptions(); |
|
207 |
boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT); |
|
208 |
for (Test<?> test : serverSocketTests) { |
|
209 |
if (!(test.option == StandardSocketOptions.SO_REUSEPORT && !reuseport)) { |
|
210 |
test(ss, test); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
211 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
212 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
213 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
214 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
215 |
|
55102 | 216 |
static void doDatagramSocketTests() throws Exception { |
217 |
try (DatagramSocket ds = new DatagramSocket(0)) { |
|
218 |
Set<SocketOption<?>> options = ds.supportedOptions(); |
|
36115 | 219 |
boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT); |
55102 | 220 |
for (Test<?> test : datagramSocketTests) { |
36115 | 221 |
if (!(test.option == StandardSocketOptions.SO_REUSEPORT && !reuseport)) { |
55102 | 222 |
test(ds, test); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
223 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
224 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
225 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
226 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
227 |
|
55102 | 228 |
static void doMulticastSocketTests() throws Exception { |
229 |
try (MulticastSocket ms = new MulticastSocket(0)) { |
|
230 |
for (Test<?> test : multicastSocketTests) { |
|
231 |
test(ms, test); |
|
232 |
} |
|
233 |
} |
|
234 |
} |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
235 |
|
55102 | 236 |
static Object legacyGetOption(Class<?> type, Object s, Object option) throws Exception { |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
237 |
if (type.equals(Socket.class)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
238 |
Socket socket = (Socket)s; |
36115 | 239 |
Set<SocketOption<?>> options = socket.supportedOptions(); |
240 |
boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
241 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
242 |
if (option.equals(StandardSocketOptions.SO_KEEPALIVE)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
243 |
return Boolean.valueOf(socket.getKeepAlive()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
244 |
} else if (option.equals(StandardSocketOptions.SO_SNDBUF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
245 |
return Integer.valueOf(socket.getSendBufferSize()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
246 |
} else if (option.equals(StandardSocketOptions.SO_RCVBUF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
247 |
return Integer.valueOf(socket.getReceiveBufferSize()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
248 |
} else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
249 |
return Boolean.valueOf(socket.getReuseAddress()); |
36115 | 250 |
} else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) { |
251 |
return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT)); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
252 |
} else if (option.equals(StandardSocketOptions.SO_LINGER)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
253 |
return Integer.valueOf(socket.getSoLinger()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
254 |
} else if (option.equals(StandardSocketOptions.IP_TOS)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
255 |
return Integer.valueOf(socket.getTrafficClass()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
256 |
} else if (option.equals(StandardSocketOptions.TCP_NODELAY)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
257 |
return Boolean.valueOf(socket.getTcpNoDelay()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
258 |
} else { |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
259 |
throw new RuntimeException("unexpected socket option"); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
260 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
261 |
} else if (type.equals(ServerSocket.class)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
262 |
ServerSocket socket = (ServerSocket)s; |
36115 | 263 |
Set<SocketOption<?>> options = socket.supportedOptions(); |
264 |
boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT); |
|
265 |
||
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
266 |
if (option.equals(StandardSocketOptions.SO_RCVBUF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
267 |
return Integer.valueOf(socket.getReceiveBufferSize()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
268 |
} else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
269 |
return Boolean.valueOf(socket.getReuseAddress()); |
36115 | 270 |
} else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) { |
271 |
return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT)); |
|
30963
88469d06e03f
8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents:
23879
diff
changeset
|
272 |
} else if (option.equals(StandardSocketOptions.IP_TOS)) { |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
273 |
return getServerSocketTrafficClass(socket); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
274 |
} else { |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
275 |
throw new RuntimeException("unexpected socket option"); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
276 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
277 |
} else if (type.equals(DatagramSocket.class)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
278 |
DatagramSocket socket = (DatagramSocket)s; |
36115 | 279 |
Set<SocketOption<?>> options = socket.supportedOptions(); |
280 |
boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
281 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
282 |
if (option.equals(StandardSocketOptions.SO_SNDBUF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
283 |
return Integer.valueOf(socket.getSendBufferSize()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
284 |
} else if (option.equals(StandardSocketOptions.SO_RCVBUF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
285 |
return Integer.valueOf(socket.getReceiveBufferSize()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
286 |
} else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
287 |
return Boolean.valueOf(socket.getReuseAddress()); |
36115 | 288 |
} else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) { |
289 |
return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT)); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
290 |
} else if (option.equals(StandardSocketOptions.IP_TOS)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
291 |
return Integer.valueOf(socket.getTrafficClass()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
292 |
} else { |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
293 |
throw new RuntimeException("unexpected socket option"); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
294 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
295 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
296 |
} else if (type.equals(MulticastSocket.class)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
297 |
MulticastSocket socket = (MulticastSocket)s; |
36115 | 298 |
Set<SocketOption<?>> options = socket.supportedOptions(); |
299 |
boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
300 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
301 |
if (option.equals(StandardSocketOptions.SO_SNDBUF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
302 |
return Integer.valueOf(socket.getSendBufferSize()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
303 |
} else if (option.equals(StandardSocketOptions.SO_RCVBUF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
304 |
return Integer.valueOf(socket.getReceiveBufferSize()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
305 |
} else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
306 |
return Boolean.valueOf(socket.getReuseAddress()); |
36115 | 307 |
} else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) { |
308 |
return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT)); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
309 |
} else if (option.equals(StandardSocketOptions.IP_TOS)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
310 |
return Integer.valueOf(socket.getTrafficClass()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
311 |
} else if (option.equals(StandardSocketOptions.IP_MULTICAST_IF)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
312 |
return socket.getNetworkInterface(); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
313 |
} else if (option.equals(StandardSocketOptions.IP_MULTICAST_TTL)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
314 |
return Integer.valueOf(socket.getTimeToLive()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
315 |
} else if (option.equals(StandardSocketOptions.IP_MULTICAST_LOOP)) { |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
316 |
return Boolean.valueOf(socket.getLoopbackMode()); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
317 |
} else { |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
318 |
throw new RuntimeException("unexpected socket option"); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
319 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
320 |
} |
55226
ce8bab2c4185
8225214: Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER
chegar
parents:
55102
diff
changeset
|
321 |
throw new RuntimeException("unexpected socket type"); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
322 |
} |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
323 |
|
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
324 |
public static void main(String args[]) throws Exception { |
54811
9db7c0f561a6
8223652: Rename IPSupport.skipIfCurrentConfigurationIsInvalid() to IPSupport.throwSkippedExceptionIfNonOperational()
aeubanks
parents:
54770
diff
changeset
|
325 |
IPSupport.throwSkippedExceptionIfNonOperational(); |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
326 |
doSocketTests(); |
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
327 |
doServerSocketTests(); |
55102 | 328 |
doDatagramSocketTests(); |
329 |
doMulticastSocketTests(); |
|
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
330 |
} |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
331 |
|
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
332 |
// Reflectively access jdk.net.Sockets.getOption so that the test can run |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
333 |
// without the jdk.net module. |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
334 |
static Object getServerSocketTrafficClass(ServerSocket ss) throws Exception { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
335 |
try { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
336 |
Class<?> c = Class.forName("jdk.net.Sockets"); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
337 |
Method m = c.getDeclaredMethod("getOption", ServerSocket.class, SocketOption.class); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
338 |
return m.invoke(null, ss, StandardSocketOptions.IP_TOS); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
339 |
} catch (ClassNotFoundException e) { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
340 |
// Ok, jdk.net module not present, just fall back |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
341 |
System.out.println("jdk.net module not present, falling back."); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
342 |
return Integer.valueOf(ss.getOption(StandardSocketOptions.IP_TOS)); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
343 |
} catch (ReflectiveOperationException e) { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
344 |
throw new AssertionError(e); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
345 |
} |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
36115
diff
changeset
|
346 |
} |
23879
284802a2d355
8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff
changeset
|
347 |
} |