1 /* 2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4927640 26 * @summary Tests the SCTP protocol implementation 27 * @author chegar 28 */ 29 30 import java.io.IOException; 31 import java.util.Set; 32 import java.net.InetSocketAddress; 33 import java.net.SocketAddress; 34 import java.util.List; 35 import java.util.Arrays; 36 import java.util.Iterator; 37 import java.nio.channels.ClosedChannelException; 38 import com.sun.nio.sctp.SctpChannel; 39 import com.sun.nio.sctp.SctpServerChannel; 40 import com.sun.nio.sctp.SctpSocketOption; 41 import java.security.AccessController; 42 import sun.security.action.GetPropertyAction; 43 import static com.sun.nio.sctp.SctpStandardSocketOptions.*; 44 import static java.lang.System.out; 45 46 public class SocketOptionTests { 47 final String osName = AccessController.doPrivileged( 48 new GetPropertyAction("os.name")); 49 50 <T> void checkOption(SctpChannel sc, SctpSocketOption<T> name, 51 T expectedValue) throws IOException { 52 T value = sc.getOption(name); 53 check(value.equals(expectedValue), name + ": value (" + value + 54 ") not as expected (" + expectedValue + ")"); 55 } 56 57 <T> void optionalSupport(SctpChannel sc, SctpSocketOption<T> name, 58 T value) { 59 try { 60 sc.setOption(name, value); 61 checkOption(sc, name, value); 62 } catch (IOException e) { 63 /* Informational only, not all options have native support */ 64 out.println(name + " not supported. " + e); 65 } 66 } 67 68 void test(String[] args) { | 1 /* 2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4927640 26 * @summary Tests the SCTP protocol implementation 27 * @author chegar 28 */ 29 30 import java.io.IOException; 31 import java.util.Set; 32 import java.net.InetSocketAddress; 33 import java.net.SocketAddress; 34 import java.util.List; 35 import java.util.Arrays; 36 import java.util.Iterator; 37 import java.nio.channels.ClosedChannelException; 38 import com.sun.nio.sctp.SctpChannel; 39 import com.sun.nio.sctp.SctpServerChannel; 40 import com.sun.nio.sctp.SctpSocketOption; 41 import java.security.AccessController; 42 import java.security.PrivilegedAction; 43 import static com.sun.nio.sctp.SctpStandardSocketOptions.*; 44 import static java.lang.System.out; 45 46 public class SocketOptionTests { 47 final String osName = AccessController.doPrivileged( 48 (PrivilegedAction<String>)() -> System.getProperty("os.name")); 49 50 <T> void checkOption(SctpChannel sc, SctpSocketOption<T> name, 51 T expectedValue) throws IOException { 52 T value = sc.getOption(name); 53 check(value.equals(expectedValue), name + ": value (" + value + 54 ") not as expected (" + expectedValue + ")"); 55 } 56 57 <T> void optionalSupport(SctpChannel sc, SctpSocketOption<T> name, 58 T value) { 59 try { 60 sc.setOption(name, value); 61 checkOption(sc, name, value); 62 } catch (IOException e) { 63 /* Informational only, not all options have native support */ 64 out.println(name + " not supported. " + e); 65 } 66 } 67 68 void test(String[] args) { |