Search in sources :

Example 1 with SctpSocketOption

use of com.sun.nio.sctp.SctpSocketOption in project jdk8u_jdk by JetBrains.

the class SocketOptionTests method test.

void test(String[] args) {
    if (!Util.isSCTPSupported()) {
        out.println("SCTP protocol is not supported");
        out.println("Test cannot be run");
        return;
    }
    try {
        SctpMultiChannel smc = SctpMultiChannel.open();
        /* check supported options */
        Set<SctpSocketOption<?>> options = smc.supportedOptions();
        List<? extends SctpSocketOption<?>> expected = Arrays.<SctpSocketOption<?>>asList(SCTP_DISABLE_FRAGMENTS, SCTP_EXPLICIT_COMPLETE, SCTP_FRAGMENT_INTERLEAVE, SCTP_INIT_MAXSTREAMS, SCTP_NODELAY, SCTP_PRIMARY_ADDR, SCTP_SET_PEER_PRIMARY_ADDR, SO_SNDBUF, SO_RCVBUF, SO_LINGER);
        for (SctpSocketOption opt : expected) {
            if (!options.contains(opt))
                fail(opt.name() + " should be supported");
        }
        InitMaxStreams streams = InitMaxStreams.create(1024, 1024);
        smc.setOption(SCTP_INIT_MAXSTREAMS, streams, null);
        checkOption(smc, SCTP_INIT_MAXSTREAMS, streams);
        streams = smc.getOption(SCTP_INIT_MAXSTREAMS, null);
        check(streams.maxInStreams() == 1024, "Max in streams: value: " + streams.maxInStreams() + ", expected 1024 ");
        check(streams.maxOutStreams() == 1024, "Max out streams: value: " + streams.maxOutStreams() + ", expected 1024 ");
        optionalSupport(smc, SCTP_DISABLE_FRAGMENTS, true);
        optionalSupport(smc, SCTP_EXPLICIT_COMPLETE, true);
        optionalSupport(smc, SCTP_FRAGMENT_INTERLEAVE, 1);
        smc.setOption(SCTP_NODELAY, true, null);
        checkOption(smc, SCTP_NODELAY, true);
        smc.setOption(SO_SNDBUF, 16 * 1024, null);
        smc.setOption(SO_RCVBUF, 16 * 1024, null);
        checkOption(smc, SO_LINGER, -1);
        /* Setting SO_LINGER not support for one-to-many on Solaris */
        if (!"SunOS".equals(osName)) {
            smc.setOption(SO_LINGER, 2000, null);
            checkOption(smc, SO_LINGER, 2000);
        }
        /* SCTP_PRIMARY_ADDR */
        sctpPrimaryAddr();
        /* NullPointerException */
        try {
            smc.setOption(null, "value", null);
            fail("NullPointerException not thrown for setOption");
        } catch (NullPointerException unused) {
            pass();
        }
        try {
            smc.getOption(null, null);
            fail("NullPointerException not thrown for getOption");
        } catch (NullPointerException unused) {
            pass();
        }
        /* ClosedChannelException */
        smc.close();
        try {
            smc.setOption(SCTP_INIT_MAXSTREAMS, streams, null);
            fail("ClosedChannelException not thrown");
        } catch (ClosedChannelException unused) {
            pass();
        }
    } catch (IOException ioe) {
        unexpected(ioe);
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) SctpSocketOption(com.sun.nio.sctp.SctpSocketOption) IOException(java.io.IOException) SctpMultiChannel(com.sun.nio.sctp.SctpMultiChannel)

Aggregations

SctpMultiChannel (com.sun.nio.sctp.SctpMultiChannel)1 SctpSocketOption (com.sun.nio.sctp.SctpSocketOption)1 IOException (java.io.IOException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1