test/jdk/java/net/SocketOption/OptionsTest.java
author alanb
Fri, 03 May 2019 08:26:44 +0100
branchniosocketimpl-branch
changeset 57347 16c087c9103e
parent 57342 5b512573ccb8
parent 54681 edd709e64ea1
child 57358 f0a1d9760c5e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
    26
 * @bug 8036979 8072384 8044773
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
    27
 * @requires !vm.graal.enabled
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    28
 * @run main/othervm -Xcheck:jni OptionsTest
30963
88469d06e03f 8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents: 23879
diff changeset
    29
 * @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
    30
 * @run main/othervm --limit-modules=java.base OptionsTest
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    31
 */
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    32
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
    33
import java.lang.reflect.Method;
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    34
import java.net.*;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    35
import java.util.*;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    36
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    37
public class OptionsTest {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    38
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    39
    static class Test<T> {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    40
        final SocketOption<T> option;
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    41
        final T value;
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    42
        Test(SocketOption<T> option, T value) {
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    43
            this.option = option;
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    44
            this.value = value;
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    45
        }
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    46
        static <T> Test<T> create(SocketOption<T> option, T value) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    47
            return new Test<T>(option, value);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    48
        }
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    49
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
    50
    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    51
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    52
    // The tests set the option using the new API, read back the set value
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    53
    // which could be diferent, and then use the legacy get API to check
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    54
    // these values are the same
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    55
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    56
    static Test<?>[] socketTests = new Test<?>[] {
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    57
        Test.create(StandardSocketOptions.SO_KEEPALIVE, Boolean.TRUE),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    58
        Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    59
        Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    60
        Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE),
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
    61
        Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE),
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    62
        Test.create(StandardSocketOptions.SO_LINGER, Integer.valueOf(80)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    63
        Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100))
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    64
    };
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    65
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    66
    static Test<?>[] serverSocketTests = new Test<?>[] {
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    67
        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
    68
        Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE),
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
    69
        Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE),
30963
88469d06e03f 8072384: Setting IP_TOS on java.net sockets not working on unix
coffeys
parents: 23879
diff changeset
    70
        Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100))
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
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    73
    static Test<?>[] datagramSocketTests = new Test<?>[] {
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    74
        Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    75
        Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    76
        Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE),
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
    77
        Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE),
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    78
        Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100))
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    79
    };
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    80
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    81
    static Test<?>[] multicastSocketTests = new Test<?>[] {
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    82
        Test.create(StandardSocketOptions.IP_MULTICAST_IF, getNetworkInterface()),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    83
        Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(10)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    84
        Test.create(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.TRUE)
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    85
    };
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    86
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    87
    static NetworkInterface getNetworkInterface() {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    88
        try {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    89
            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
    90
            while (nifs.hasMoreElements()) {
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
    91
                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
    92
                if (ni.supportsMulticast()) {
9aac81c72779 8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents: 30963
diff changeset
    93
                    return ni;
9aac81c72779 8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents: 30963
diff changeset
    94
                }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    95
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    96
        } catch (Exception e) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    97
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    98
        return null;
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
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   101
    static boolean okayToTest(Socket s, SocketOption<?> option) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   102
        if (option == StandardSocketOptions.SO_REUSEPORT) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   103
            // skip SO_REUSEPORT if option is not supported
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   104
            return s.supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   105
        }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   106
        if (option == StandardSocketOptions.IP_TOS && s.isConnected()) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   107
            // skip IP_TOS if connected
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   108
            return false;
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   109
        }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   110
        return true;
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   111
    }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   112
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   113
    static <T> void testEqual(SocketOption<T> option, T value1, T value2) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   114
        if (!value1.equals(value2)) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   115
            throw new RuntimeException("Test of " + option.name() + " failed: "
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   116
                    + value1 + " != " + value2);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   117
        }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   118
    }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   119
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   120
    static <T> void test(Socket s, Test<T> test) throws Exception {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   121
        SocketOption<T> option = test.option;
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   122
        s.setOption(option, test.value);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   123
        T value1 = s.getOption(test.option);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   124
        T value2 = (T) legacyGetOption(Socket.class, s, test.option);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   125
        testEqual(option, value1, value2);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   126
    }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   127
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   128
    static <T> void test(ServerSocket ss, Test<T> test) throws Exception {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   129
        SocketOption<T> option = test.option;
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   130
        ss.setOption(option, test.value);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   131
        T value1 = ss.getOption(test.option);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   132
        T value2 = (T) legacyGetOption(ServerSocket.class, ss, test.option);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   133
        testEqual(option, value1, value2);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   134
    }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   135
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   136
    static <T> void test(DatagramSocket ds, Test<T> test) throws Exception {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   137
        SocketOption<T> option = test.option;
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   138
        ds.setOption(option, test.value);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   139
        T value1 = ds.getOption(test.option);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   140
        T value2 = (T) legacyGetOption(ds.getClass(), ds, test.option);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   141
        testEqual(option, value1, value2);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   142
    }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   143
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   144
    @SuppressWarnings("try")
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   145
    static void doSocketTests() throws Exception {
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   146
        // unconnected socket
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   147
        try (Socket s = new Socket()) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   148
            for (Test<?> test : socketTests) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   149
                if (okayToTest(s, test.option)) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   150
                    test(s, test);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   151
                }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   152
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   153
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   154
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   155
        // connected socket
57342
5b512573ccb8 More test cleanup
alanb
parents: 57336
diff changeset
   156
        try (ServerSocket ss = new ServerSocket()) {
5b512573ccb8 More test cleanup
alanb
parents: 57336
diff changeset
   157
            var loopback = InetAddress.getLoopbackAddress();
5b512573ccb8 More test cleanup
alanb
parents: 57336
diff changeset
   158
            ss.bind(new InetSocketAddress(loopback, 0));
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   159
            try (Socket s1 = new Socket()) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   160
                s1.connect(ss.getLocalSocketAddress());
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   161
                try (Socket s2 = ss.accept()) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   162
                    for (Test<?> test : socketTests) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   163
                        if (okayToTest(s1, test.option)) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   164
                            test(s1, test);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   165
                        }
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   166
                    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   167
                }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   168
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   169
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   170
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   171
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   172
    static void doServerSocketTests() throws Exception {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   173
        try (ServerSocket ss = new ServerSocket(0)) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   174
            Set<SocketOption<?>> options = ss.supportedOptions();
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   175
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   176
            for (Test<?> test : serverSocketTests) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   177
                if (!(test.option == StandardSocketOptions.SO_REUSEPORT && !reuseport)) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   178
                    test(ss, test);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   179
                }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   180
            }
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
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   184
    static void doDatagramSocketTests() throws Exception {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   185
        try (DatagramSocket ds = new DatagramSocket(0)) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   186
            Set<SocketOption<?>> options = ds.supportedOptions();
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   187
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   188
            for (Test<?> test : datagramSocketTests) {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   189
                if (!(test.option == StandardSocketOptions.SO_REUSEPORT && !reuseport)) {
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   190
                    test(ds, test);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   191
                }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   192
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   193
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   194
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   195
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   196
    static void doMulticastSocketTests() throws Exception {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   197
        try (MulticastSocket ms = new MulticastSocket(0)) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   198
            for (Test<?> test : multicastSocketTests) {
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   199
                test(ms, test);
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   200
            }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   201
        }
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   202
    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   203
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   204
    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
   205
        if (type.equals(Socket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   206
            Socket socket = (Socket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   207
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   208
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   209
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   210
            if (option.equals(StandardSocketOptions.SO_KEEPALIVE)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   211
                return Boolean.valueOf(socket.getKeepAlive());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   212
            } else if (option.equals(StandardSocketOptions.SO_SNDBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   213
                return Integer.valueOf(socket.getSendBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   214
            } else if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   215
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   216
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   217
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   218
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   219
                return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT));
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   220
            } else if (option.equals(StandardSocketOptions.SO_LINGER)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   221
                return Integer.valueOf(socket.getSoLinger());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   222
            } else if (option.equals(StandardSocketOptions.IP_TOS)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   223
                return Integer.valueOf(socket.getTrafficClass());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   224
            } else if (option.equals(StandardSocketOptions.TCP_NODELAY)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   225
                return Boolean.valueOf(socket.getTcpNoDelay());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   226
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   227
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   228
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   229
        } else if  (type.equals(ServerSocket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   230
            ServerSocket socket = (ServerSocket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   231
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   232
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   233
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   234
            if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   235
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   236
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   237
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   238
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   239
                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
   240
            } 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
   241
                return getServerSocketTrafficClass(socket);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   242
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   243
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   244
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   245
        } else if  (type.equals(DatagramSocket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   246
            DatagramSocket socket = (DatagramSocket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   247
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   248
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   249
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   250
            if (option.equals(StandardSocketOptions.SO_SNDBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   251
                return Integer.valueOf(socket.getSendBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   252
            } else if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   253
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   254
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   255
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   256
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   257
                return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT));
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   258
            } else if (option.equals(StandardSocketOptions.IP_TOS)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   259
                return Integer.valueOf(socket.getTrafficClass());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   260
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   261
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   262
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   263
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   264
        } else if  (type.equals(MulticastSocket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   265
            MulticastSocket socket = (MulticastSocket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   266
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   267
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   268
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   269
            if (option.equals(StandardSocketOptions.SO_SNDBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   270
                return Integer.valueOf(socket.getSendBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   271
            } else if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   272
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   273
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   274
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   275
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   276
                return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT));
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   277
            } else if (option.equals(StandardSocketOptions.IP_TOS)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   278
                return Integer.valueOf(socket.getTrafficClass());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   279
            } else if (option.equals(StandardSocketOptions.IP_MULTICAST_IF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   280
                return socket.getNetworkInterface();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   281
            } else if (option.equals(StandardSocketOptions.IP_MULTICAST_TTL)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   282
                return Integer.valueOf(socket.getTimeToLive());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   283
            } else if (option.equals(StandardSocketOptions.IP_MULTICAST_LOOP)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   284
                return Boolean.valueOf(socket.getLoopbackMode());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   285
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   286
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   287
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   288
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   289
        throw new RuntimeException("unexecpted socket type");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   290
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   291
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   292
    public static void main(String args[]) throws Exception {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   293
        doSocketTests();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   294
        doServerSocketTests();
57336
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   295
        doDatagramSocketTests();
766140c67efa Eliminate need to cache traffic class
alanb
parents: 54086
diff changeset
   296
        doMulticastSocketTests();
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   297
    }
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   298
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   299
    // 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
   300
    // 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
   301
    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
   302
        try {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   303
            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
   304
            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
   305
            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
   306
        } 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
   307
            // 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
   308
            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
   309
            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
   310
        } 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
   311
            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
   312
        }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   313
    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   314
}