test/jdk/java/net/SocketOption/OptionsTest.java
author kvn
Wed, 13 Dec 2017 11:59:55 -0800
changeset 48397 ead47ddf5844
parent 47216 71c04702a3d5
child 54086 ccb4a50bee06
permissions -rw-r--r--
8191788: add jdk.internal.vm.compiler to --limit-modules if -Djvmci.Compiler=graal is in the command line Summary: skip tests which use --limit-modules when Graal is used as JIT compiler. Reviewed-by: alanb, mchung, dholmes, ccheung, dnsimon
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
/*
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
     2
 * Copyright (c) 2014, 2017, 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
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    39
    static class Test {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    40
        Test(SocketOption<?> option, Object testValue) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    41
            this.option = option;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    42
            this.testValue = testValue;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    43
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    44
        static Test create (SocketOption<?> option, Object testValue) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    45
            return new Test(option, testValue);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    46
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    47
        Object option;
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    48
        Object testValue;
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
    49
    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    50
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    51
    // 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
    52
    // 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
    53
    // these values are the same
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
    static Test[] socketTests = new Test[] {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    56
        Test.create(StandardSocketOptions.SO_KEEPALIVE, Boolean.TRUE),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    57
        Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    58
        Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    59
        Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE),
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
    60
        Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE),
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    61
        Test.create(StandardSocketOptions.SO_LINGER, Integer.valueOf(80)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    62
        Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100))
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    63
    };
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
    static Test[] serverSocketTests = new Test[] {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    66
        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
    67
        Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE),
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
    68
        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
    69
        Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100))
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    70
    };
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
    static Test[] dgSocketTests = new Test[] {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    73
        Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)),
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)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    75
        Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE),
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
    76
        Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE),
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    77
        Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100))
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    78
    };
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
    static Test[] mcSocketTests = new Test[] {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    81
        Test.create(StandardSocketOptions.IP_MULTICAST_IF, getNetworkInterface()),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    82
        Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(10)),
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    83
        Test.create(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.TRUE)
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    84
    };
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
    static NetworkInterface getNetworkInterface() {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    87
        try {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    88
            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
    89
            while (nifs.hasMoreElements()) {
9aac81c72779 8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents: 30963
diff changeset
    90
                NetworkInterface ni = (NetworkInterface)nifs.nextElement();
9aac81c72779 8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents: 30963
diff changeset
    91
                if (ni.supportsMulticast()) {
9aac81c72779 8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents: 30963
diff changeset
    92
                    return ni;
9aac81c72779 8146482: [TESTBUG] java/net/SocketOption/OptionTest should only use multicast capable interfaces for multicast tests
simonis
parents: 30963
diff changeset
    93
                }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    94
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    95
        } catch (Exception e) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    96
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
    97
        return null;
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 void doSocketTests() throws Exception {
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
            ServerSocket srv = new ServerSocket(0);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   103
            Socket c = new Socket("127.0.0.1", srv.getLocalPort());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   104
            Socket s = srv.accept();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   105
        ) {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   106
            Set<SocketOption<?>> options = c.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   107
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   108
            for (int i=0; i<socketTests.length; i++) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   109
                Test test = socketTests[i];
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   110
                if (!(test.option == StandardSocketOptions.SO_REUSEPORT && !reuseport)) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   111
                    c.setOption((SocketOption)test.option, test.testValue);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   112
                    Object getval = c.getOption((SocketOption)test.option);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   113
                    Object legacyget = legacyGetOption(Socket.class, c,test.option);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   114
                    if (!getval.equals(legacyget)) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   115
                        Formatter f = new Formatter();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   116
                        f.format("S Err %d: %s/%s", i, getval, legacyget);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   117
                        throw new RuntimeException(f.toString());
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   118
                    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   119
                }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   120
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   121
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   122
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   123
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   124
    static void doDgSocketTests() throws Exception {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   125
        try (
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   126
            DatagramSocket c = new DatagramSocket(0);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   127
        ) {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   128
            Set<SocketOption<?>> options = c.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   129
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   130
            for (int i=0; i<dgSocketTests.length; i++) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   131
                Test test = dgSocketTests[i];
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   132
                if (!(test.option == StandardSocketOptions.SO_REUSEPORT && !reuseport)) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   133
                    c.setOption((SocketOption)test.option, test.testValue);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   134
                    Object getval = c.getOption((SocketOption)test.option);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   135
                    Object legacyget = legacyGetOption(DatagramSocket.class, c,test.option);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   136
                    if (!getval.equals(legacyget)) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   137
                        Formatter f = new Formatter();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   138
                        f.format("DG Err %d: %s/%s", i, getval, legacyget);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   139
                        throw new RuntimeException(f.toString());
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   140
                    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   141
                }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   142
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   143
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   144
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   145
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   146
    static void doMcSocketTests() throws Exception {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   147
        try (
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   148
            MulticastSocket c = new MulticastSocket(0);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   149
        ) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   150
            for (int i=0; i<mcSocketTests.length; i++) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   151
                Test test = mcSocketTests[i];
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   152
                c.setOption((SocketOption)test.option, test.testValue);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   153
                Object getval = c.getOption((SocketOption)test.option);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   154
                Object legacyget = legacyGetOption(MulticastSocket.class, c,test.option);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   155
                if (!getval.equals(legacyget)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   156
                    Formatter f = new Formatter();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   157
                    f.format("MC Err %d: %s/%s", i, getval, legacyget);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   158
                    throw new RuntimeException(f.toString());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   159
                }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   160
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   161
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   162
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   163
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   164
    static void doServerSocketTests() throws Exception {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   165
        try (
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   166
            ServerSocket c = new ServerSocket(0);
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   167
        ) {
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   168
            Set<SocketOption<?>> options = c.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   169
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   170
            for (int i=0; i<serverSocketTests.length; i++) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   171
                Test test = serverSocketTests[i];
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   172
                if (!(test.option == StandardSocketOptions.SO_REUSEPORT && !reuseport)) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   173
                    c.setOption((SocketOption)test.option, test.testValue);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   174
                    Object getval = c.getOption((SocketOption)test.option);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   175
                    Object legacyget = legacyGetOption(
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   176
                        ServerSocket.class, c, test.option
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   177
                    );
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   178
                    if (!getval.equals(legacyget)) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   179
                        Formatter f = new Formatter();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   180
                        f.format("SS Err %d: %s/%s", i, getval, legacyget);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   181
                        throw new RuntimeException(f.toString());
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   182
                    }
23879
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
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   185
        }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   186
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   187
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   188
    static Object legacyGetOption(
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   189
        Class<?> type, Object s, Object option)
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   190
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   191
        throws Exception
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
        if (type.equals(Socket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   194
            Socket socket = (Socket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   195
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   196
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
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
            if (option.equals(StandardSocketOptions.SO_KEEPALIVE)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   199
                return Boolean.valueOf(socket.getKeepAlive());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   200
            } else if (option.equals(StandardSocketOptions.SO_SNDBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   201
                return Integer.valueOf(socket.getSendBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   202
            } else if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   203
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   204
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   205
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   206
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   207
                return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT));
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   208
            } else if (option.equals(StandardSocketOptions.SO_LINGER)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   209
                return Integer.valueOf(socket.getSoLinger());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   210
            } else if (option.equals(StandardSocketOptions.IP_TOS)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   211
                return Integer.valueOf(socket.getTrafficClass());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   212
            } else if (option.equals(StandardSocketOptions.TCP_NODELAY)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   213
                return Boolean.valueOf(socket.getTcpNoDelay());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   214
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   215
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   216
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   217
        } else if  (type.equals(ServerSocket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   218
            ServerSocket socket = (ServerSocket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   219
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   220
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   221
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   222
            if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   223
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   224
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   225
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   226
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   227
                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
   228
            } 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
   229
                return getServerSocketTrafficClass(socket);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   230
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   231
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   232
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   233
        } else if  (type.equals(DatagramSocket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   234
            DatagramSocket socket = (DatagramSocket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   235
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   236
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   237
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   238
            if (option.equals(StandardSocketOptions.SO_SNDBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   239
                return Integer.valueOf(socket.getSendBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   240
            } else if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   241
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   242
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   243
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   244
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   245
                return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT));
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   246
            } else if (option.equals(StandardSocketOptions.IP_TOS)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   247
                return Integer.valueOf(socket.getTrafficClass());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   248
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   249
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   250
            }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   251
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   252
        } else if  (type.equals(MulticastSocket.class)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   253
            MulticastSocket socket = (MulticastSocket)s;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   254
            Set<SocketOption<?>> options = socket.supportedOptions();
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   255
            boolean reuseport = options.contains(StandardSocketOptions.SO_REUSEPORT);
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   256
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   257
            if (option.equals(StandardSocketOptions.SO_SNDBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   258
                return Integer.valueOf(socket.getSendBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   259
            } else if (option.equals(StandardSocketOptions.SO_RCVBUF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   260
                return Integer.valueOf(socket.getReceiveBufferSize());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   261
            } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   262
                return Boolean.valueOf(socket.getReuseAddress());
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   263
            } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 34889
diff changeset
   264
                return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT));
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   265
            } else if (option.equals(StandardSocketOptions.IP_TOS)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   266
                return Integer.valueOf(socket.getTrafficClass());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   267
            } else if (option.equals(StandardSocketOptions.IP_MULTICAST_IF)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   268
                return socket.getNetworkInterface();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   269
            } else if (option.equals(StandardSocketOptions.IP_MULTICAST_TTL)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   270
                return Integer.valueOf(socket.getTimeToLive());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   271
            } else if (option.equals(StandardSocketOptions.IP_MULTICAST_LOOP)) {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   272
                return Boolean.valueOf(socket.getLoopbackMode());
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   273
            } else {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   274
                throw new RuntimeException("unexecpted socket option");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   275
            }
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
        throw new RuntimeException("unexecpted socket type");
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   278
    }
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   279
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   280
    public static void main(String args[]) throws Exception {
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   281
        doSocketTests();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   282
        doServerSocketTests();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   283
        doDgSocketTests();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   284
        doMcSocketTests();
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   285
    }
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   286
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   287
    // 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
   288
    // 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
   289
    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
   290
        try {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   291
            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
   292
            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
   293
            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
   294
        } 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
   295
            // 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
   296
            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
   297
            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
   298
        } 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
   299
            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
   300
        }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 36115
diff changeset
   301
    }
23879
284802a2d355 8036979: Support java.net.SocketOption<> in java.net socket types
michaelm
parents:
diff changeset
   302
}