< prev index next >

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

Print this page
rev 59105 : imported patch corelibs


  99             InitMaxStreams streams = InitMaxStreams.create(1024, 1024);
 100             smc.setOption(SCTP_INIT_MAXSTREAMS, streams, null);
 101             checkOption(smc, SCTP_INIT_MAXSTREAMS, streams);
 102             streams = smc.getOption(SCTP_INIT_MAXSTREAMS, null);
 103             check(streams.maxInStreams() == 1024, "Max in streams: value: "
 104                     + streams.maxInStreams() + ", expected 1024 ");
 105             check(streams.maxOutStreams() == 1024, "Max out streams: value: "
 106                     + streams.maxOutStreams() + ", expected 1024 ");
 107 
 108             optionalSupport(smc, SCTP_DISABLE_FRAGMENTS, true);
 109             optionalSupport(smc, SCTP_EXPLICIT_COMPLETE, true);
 110             optionalSupport(smc, SCTP_FRAGMENT_INTERLEAVE, 1);
 111 
 112             smc.setOption(SCTP_NODELAY, true, null);
 113             checkOption(smc, SCTP_NODELAY, true);
 114             smc.setOption(SO_SNDBUF, 16*1024, null);
 115             smc.setOption(SO_RCVBUF, 16*1024, null);
 116 
 117             checkOption(smc, SO_LINGER, -1);  /* default should be negative */
 118 
 119             /* Setting SO_LINGER not support for one-to-many on Solaris */
 120             if (!"SunOS".equals(osName)) {
 121                 smc.setOption(SO_LINGER, 2000, null);
 122                 checkOption(smc, SO_LINGER, 2000);
 123             }
 124 
 125             /* SCTP_PRIMARY_ADDR */
 126             sctpPrimaryAddr();
 127 
 128             /* NullPointerException */
 129             try {
 130                 smc.setOption(null, "value", null);
 131                 fail("NullPointerException not thrown for setOption");
 132             } catch (NullPointerException unused) {
 133                 pass();
 134             }
 135             try {
 136                smc.getOption(null, null);
 137                fail("NullPointerException not thrown for getOption");
 138             } catch (NullPointerException unused) {
 139                pass();
 140             }
 141 
 142             /* ClosedChannelException */
 143             smc.close();


 178         int sent = smc.send(buffer, info);
 179 
 180         /* Receive the COMM_UP */
 181         buffer.clear();
 182         SOTNotificationHandler handler = new SOTNotificationHandler();
 183         info = smc.receive(buffer, null, handler);
 184         check(handler.receivedCommUp(), "COMM_UP no received");
 185         Set<Association> associations = smc.associations();
 186         check(!associations.isEmpty(),"There should be some associations");
 187         Association assoc = associations.iterator().next();
 188 
 189         SctpChannel peerChannel = ssc.accept();
 190         ssc.close();
 191         Set<SocketAddress> remoteAddresses = smc.getRemoteAddresses(assoc);
 192         debug("Remote Addresses: ");
 193         for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 194             InetSocketAddress addr = (InetSocketAddress)it.next();
 195             debug("\t" + addr);
 196         }
 197 
 198         /* retrieval of SCTP_PRIMARY_ADDR is not supported on Solaris */
 199         if ("SunOS".equals(osName)) {
 200             /* For now do not set this option. There is a bug on Solaris 10 pre Update 5
 201              * where setting this option returns Invalid argument */
 202             //debug("Set SCTP_PRIMARY_ADDR with " + addrToSet);
 203             //smc.setOption(SCTP_PRIMARY_ADDR, addrToSet, assoc);
 204             return;
 205         } else { /* Linux */
 206             SocketAddress primaryAddr = smc.getOption(SCTP_PRIMARY_ADDR, assoc);
 207             System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
 208             /* Verify that this is one of the remote addresses */
 209             check(remoteAddresses.contains(primaryAddr), "SCTP_PRIMARY_ADDR returned bogus address!");
 210 
 211             for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 212                 InetSocketAddress addrToSet = (InetSocketAddress) it.next();
 213                 System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
 214                 smc.setOption(SCTP_PRIMARY_ADDR, addrToSet, assoc);
 215                 System.out.println("SCTP_PRIMARY_ADDR set to    : " + addrToSet);
 216                 primaryAddr = smc.getOption(SCTP_PRIMARY_ADDR, assoc);
 217                 System.out.println("SCTP_PRIMARY_ADDR returned  : " + primaryAddr);
 218                 check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly");
 219             }
 220         }
 221         smc.close();
 222         peerChannel.close();
 223     }
 224 
 225     class SOTNotificationHandler extends AbstractNotificationHandler<Object>
 226     {
 227         boolean receivedCommUp;  // false
 228 
 229         boolean receivedCommUp() {
 230             return receivedCommUp;
 231         }
 232 
 233         @Override
 234         public HandlerResult handleNotification(
 235                 AssociationChangeNotification notification, Object attachment) {
 236             AssocChangeEvent event = notification.event();
 237             debug("AssociationChangeNotification");
 238             debug("  Association: " + notification.association());
 239             debug("  Event: " + event);




  99             InitMaxStreams streams = InitMaxStreams.create(1024, 1024);
 100             smc.setOption(SCTP_INIT_MAXSTREAMS, streams, null);
 101             checkOption(smc, SCTP_INIT_MAXSTREAMS, streams);
 102             streams = smc.getOption(SCTP_INIT_MAXSTREAMS, null);
 103             check(streams.maxInStreams() == 1024, "Max in streams: value: "
 104                     + streams.maxInStreams() + ", expected 1024 ");
 105             check(streams.maxOutStreams() == 1024, "Max out streams: value: "
 106                     + streams.maxOutStreams() + ", expected 1024 ");
 107 
 108             optionalSupport(smc, SCTP_DISABLE_FRAGMENTS, true);
 109             optionalSupport(smc, SCTP_EXPLICIT_COMPLETE, true);
 110             optionalSupport(smc, SCTP_FRAGMENT_INTERLEAVE, 1);
 111 
 112             smc.setOption(SCTP_NODELAY, true, null);
 113             checkOption(smc, SCTP_NODELAY, true);
 114             smc.setOption(SO_SNDBUF, 16*1024, null);
 115             smc.setOption(SO_RCVBUF, 16*1024, null);
 116 
 117             checkOption(smc, SO_LINGER, -1);  /* default should be negative */
 118 


 119             smc.setOption(SO_LINGER, 2000, null);
 120             checkOption(smc, SO_LINGER, 2000);

 121 
 122             /* SCTP_PRIMARY_ADDR */
 123             sctpPrimaryAddr();
 124 
 125             /* NullPointerException */
 126             try {
 127                 smc.setOption(null, "value", null);
 128                 fail("NullPointerException not thrown for setOption");
 129             } catch (NullPointerException unused) {
 130                 pass();
 131             }
 132             try {
 133                smc.getOption(null, null);
 134                fail("NullPointerException not thrown for getOption");
 135             } catch (NullPointerException unused) {
 136                pass();
 137             }
 138 
 139             /* ClosedChannelException */
 140             smc.close();


 175         int sent = smc.send(buffer, info);
 176 
 177         /* Receive the COMM_UP */
 178         buffer.clear();
 179         SOTNotificationHandler handler = new SOTNotificationHandler();
 180         info = smc.receive(buffer, null, handler);
 181         check(handler.receivedCommUp(), "COMM_UP no received");
 182         Set<Association> associations = smc.associations();
 183         check(!associations.isEmpty(),"There should be some associations");
 184         Association assoc = associations.iterator().next();
 185 
 186         SctpChannel peerChannel = ssc.accept();
 187         ssc.close();
 188         Set<SocketAddress> remoteAddresses = smc.getRemoteAddresses(assoc);
 189         debug("Remote Addresses: ");
 190         for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 191             InetSocketAddress addr = (InetSocketAddress)it.next();
 192             debug("\t" + addr);
 193         }
 194 








 195         SocketAddress primaryAddr = smc.getOption(SCTP_PRIMARY_ADDR, assoc);
 196         System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
 197         /* Verify that this is one of the remote addresses */
 198         check(remoteAddresses.contains(primaryAddr), "SCTP_PRIMARY_ADDR returned bogus address!");
 199 
 200         for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
 201             InetSocketAddress addrToSet = (InetSocketAddress) it.next();
 202             System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
 203             smc.setOption(SCTP_PRIMARY_ADDR, addrToSet, assoc);
 204             System.out.println("SCTP_PRIMARY_ADDR set to    : " + addrToSet);
 205             primaryAddr = smc.getOption(SCTP_PRIMARY_ADDR, assoc);
 206             System.out.println("SCTP_PRIMARY_ADDR returned  : " + primaryAddr);
 207             check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly");

 208         }
 209         smc.close();
 210         peerChannel.close();
 211     }
 212 
 213     class SOTNotificationHandler extends AbstractNotificationHandler<Object>
 214     {
 215         boolean receivedCommUp;  // false
 216 
 217         boolean receivedCommUp() {
 218             return receivedCommUp;
 219         }
 220 
 221         @Override
 222         public HandlerResult handleNotification(
 223                 AssociationChangeNotification notification, Object attachment) {
 224             AssocChangeEvent event = notification.event();
 225             debug("AssociationChangeNotification");
 226             debug("  Association: " + notification.association());
 227             debug("  Event: " + event);


< prev index next >