test/com/sun/nio/sctp/SctpMultiChannel/SocketOptionTests.java

Print this page


   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  */


  30 import java.io.IOException;
  31 import java.net.InetSocketAddress;
  32 import java.net.SocketAddress;
  33 import java.util.Iterator;
  34 import java.util.Set;
  35 import java.util.List;
  36 import java.util.Arrays;
  37 import java.nio.ByteBuffer;
  38 import java.nio.channels.ClosedChannelException;
  39 import com.sun.nio.sctp.AbstractNotificationHandler;
  40 import com.sun.nio.sctp.Association;
  41 import com.sun.nio.sctp.AssociationChangeNotification;
  42 import com.sun.nio.sctp.AssociationChangeNotification.AssocChangeEvent;
  43 import com.sun.nio.sctp.HandlerResult;
  44 import com.sun.nio.sctp.MessageInfo;
  45 import com.sun.nio.sctp.SctpChannel;
  46 import com.sun.nio.sctp.SctpMultiChannel;
  47 import com.sun.nio.sctp.SctpServerChannel;
  48 import com.sun.nio.sctp.SctpSocketOption;
  49 import java.security.AccessController;
  50 import sun.security.action.GetPropertyAction;
  51 import static com.sun.nio.sctp.SctpStandardSocketOptions.*;
  52 import static java.lang.System.out;
  53 
  54 public class SocketOptionTests {
  55     final String osName = AccessController.doPrivileged(
  56                     new GetPropertyAction("os.name"));
  57 
  58     <T> void checkOption(SctpMultiChannel smc, SctpSocketOption<T> name,
  59             T expectedValue) throws IOException {
  60         T value = smc.getOption(name, null);
  61         check(value.equals(expectedValue), name + ": value (" + value +
  62                 ") not as expected (" + expectedValue + ")");
  63        }
  64 
  65     <T> void optionalSupport(SctpMultiChannel smc, SctpSocketOption<T> name,
  66             T value) {
  67         try {
  68             smc.setOption(name, value, null);
  69             checkOption(smc, name, value);
  70         } catch (IOException e) {
  71             /* Informational only, not all options have native support */
  72             out.println(name + " not supported. " + e);
  73         }
  74     }
  75 
  76     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  */


  30 import java.io.IOException;
  31 import java.net.InetSocketAddress;
  32 import java.net.SocketAddress;
  33 import java.util.Iterator;
  34 import java.util.Set;
  35 import java.util.List;
  36 import java.util.Arrays;
  37 import java.nio.ByteBuffer;
  38 import java.nio.channels.ClosedChannelException;
  39 import com.sun.nio.sctp.AbstractNotificationHandler;
  40 import com.sun.nio.sctp.Association;
  41 import com.sun.nio.sctp.AssociationChangeNotification;
  42 import com.sun.nio.sctp.AssociationChangeNotification.AssocChangeEvent;
  43 import com.sun.nio.sctp.HandlerResult;
  44 import com.sun.nio.sctp.MessageInfo;
  45 import com.sun.nio.sctp.SctpChannel;
  46 import com.sun.nio.sctp.SctpMultiChannel;
  47 import com.sun.nio.sctp.SctpServerChannel;
  48 import com.sun.nio.sctp.SctpSocketOption;
  49 import java.security.AccessController;
  50 import java.security.PrivilegedAction;
  51 import static com.sun.nio.sctp.SctpStandardSocketOptions.*;
  52 import static java.lang.System.out;
  53 
  54 public class SocketOptionTests {
  55     final String osName = AccessController.doPrivileged(
  56                     (PrivilegedAction<String>)() -> System.getProperty("os.name"));
  57 
  58     <T> void checkOption(SctpMultiChannel smc, SctpSocketOption<T> name,
  59             T expectedValue) throws IOException {
  60         T value = smc.getOption(name, null);
  61         check(value.equals(expectedValue), name + ": value (" + value +
  62                 ") not as expected (" + expectedValue + ")");
  63        }
  64 
  65     <T> void optionalSupport(SctpMultiChannel smc, SctpSocketOption<T> name,
  66             T value) {
  67         try {
  68             smc.setOption(name, value, null);
  69             checkOption(smc, name, value);
  70         } catch (IOException e) {
  71             /* Informational only, not all options have native support */
  72             out.println(name + " not supported. " + e);
  73         }
  74     }
  75 
  76     void test(String[] args) {