< prev index next >

test/jdk/com/sun/nio/sctp/SctpChannel/SocketOptionTests.java

Print this page
rev 59383 : [mq]: final
   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  */


 145         System.out.println("TESTING SCTP_PRIMARY_ADDR");
 146         SctpChannel sc = SctpChannel.open();
 147         SctpServerChannel ssc = SctpServerChannel.open().bind(null);
 148         Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
 149         if (addrs.isEmpty())
 150             debug("addrs should not be empty");
 151         debug("Listening on " + addrs);
 152 
 153         InetSocketAddress serverAddr = (InetSocketAddress) addrs.iterator().next();
 154         debug("connecting to " + serverAddr);
 155         sc.connect(serverAddr);
 156         SctpChannel peerChannel = ssc.accept();
 157         ssc.close();
 158         Set<SocketAddress> remoteAddresses = sc.getRemoteAddresses();
 159         debug("Remote Addresses: ");
 160         for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 161             InetSocketAddress addr = (InetSocketAddress)it.next();
 162             debug("\t" + addr);
 163         }
 164 
 165         /* retrieval of SCTP_PRIMARY_ADDR is not supported on Solaris */
 166         if ("SunOS".equals(osName)) {
 167             /* For now do not set this option. There is a bug on Solaris 10 pre Update 5
 168              * where setting this option returns Invalid argument */
 169             //debug("Set SCTP_PRIMARY_ADDR with " + addrToSet);
 170             //sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
 171             return;
 172         } else { /* Linux */
 173             SocketAddress primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
 174             System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
 175             /* Verify that this is one of the remote addresses */
 176             check(remoteAddresses.contains(primaryAddr), "SCTP_PRIMARY_ADDR returned bogus address!");
 177 
 178             for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 179                 InetSocketAddress addrToSet = (InetSocketAddress) it.next();
 180                 System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
 181                 sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
 182                 System.out.println("SCTP_PRIMARY_ADDR set to    : " + addrToSet);
 183                 primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
 184                 System.out.println("SCTP_PRIMARY_ADDR returned  : " + primaryAddr);
 185                 check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly");
 186             }
 187         }
 188         sc.close();
 189         peerChannel.close();
 190     }
 191             //--------------------- Infrastructure ---------------------------
 192     boolean debug = true;
 193     volatile int passed = 0, failed = 0;
 194     void pass() {passed++;}
 195     void fail() {failed++; Thread.dumpStack();}
 196     void fail(String msg) {System.err.println(msg); fail();}
 197     void unexpected(Throwable t) {failed++; t.printStackTrace();}
 198     void check(boolean cond) {if (cond) pass(); else fail();}
 199     void check(boolean cond, String failMessage) {if (cond) pass(); else fail(failMessage);}
 200     void debug(String message) {if(debug) { System.out.println(message); }  }
 201     public static void main(String[] args) throws Throwable {
 202         Class<?> k = new Object(){}.getClass().getEnclosingClass();
 203         try {k.getMethod("instanceMain",String[].class)
 204                 .invoke( k.newInstance(), (Object) args);}
 205         catch (Throwable e) {throw e.getCause();}}
 206     public void instanceMain(String[] args) throws Throwable {
   1 /*
   2  * Copyright (c) 2009, 2020, 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  */


 145         System.out.println("TESTING SCTP_PRIMARY_ADDR");
 146         SctpChannel sc = SctpChannel.open();
 147         SctpServerChannel ssc = SctpServerChannel.open().bind(null);
 148         Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
 149         if (addrs.isEmpty())
 150             debug("addrs should not be empty");
 151         debug("Listening on " + addrs);
 152 
 153         InetSocketAddress serverAddr = (InetSocketAddress) addrs.iterator().next();
 154         debug("connecting to " + serverAddr);
 155         sc.connect(serverAddr);
 156         SctpChannel peerChannel = ssc.accept();
 157         ssc.close();
 158         Set<SocketAddress> remoteAddresses = sc.getRemoteAddresses();
 159         debug("Remote Addresses: ");
 160         for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 161             InetSocketAddress addr = (InetSocketAddress)it.next();
 162             debug("\t" + addr);
 163         }
 164 








 165         SocketAddress primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
 166         System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
 167         /* Verify that this is one of the remote addresses */
 168         check(remoteAddresses.contains(primaryAddr), "SCTP_PRIMARY_ADDR returned bogus address!");
 169 
 170         for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 171             InetSocketAddress addrToSet = (InetSocketAddress) it.next();
 172             System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
 173             sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
 174             System.out.println("SCTP_PRIMARY_ADDR set to    : " + addrToSet);
 175             primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
 176             System.out.println("SCTP_PRIMARY_ADDR returned  : " + primaryAddr);
 177             check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly");

 178         }
 179         sc.close();
 180         peerChannel.close();
 181     }
 182             //--------------------- Infrastructure ---------------------------
 183     boolean debug = true;
 184     volatile int passed = 0, failed = 0;
 185     void pass() {passed++;}
 186     void fail() {failed++; Thread.dumpStack();}
 187     void fail(String msg) {System.err.println(msg); fail();}
 188     void unexpected(Throwable t) {failed++; t.printStackTrace();}
 189     void check(boolean cond) {if (cond) pass(); else fail();}
 190     void check(boolean cond, String failMessage) {if (cond) pass(); else fail(failMessage);}
 191     void debug(String message) {if(debug) { System.out.println(message); }  }
 192     public static void main(String[] args) throws Throwable {
 193         Class<?> k = new Object(){}.getClass().getEnclosingClass();
 194         try {k.getMethod("instanceMain",String[].class)
 195                 .invoke( k.newInstance(), (Object) args);}
 196         catch (Throwable e) {throw e.getCause();}}
 197     public void instanceMain(String[] args) throws Throwable {
< prev index next >