jdk/test/java/nio/channels/AsynchronousServerSocketChannel/Basic.java
changeset 36115 0676e37a0b9c
parent 14342 8435a30053c1
equal deleted inserted replaced
36114:a5ed9456c9be 36115:0676e37a0b9c
     1 /*
     1 /*
     2  * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   139         System.out.println("-- socket options --");
   139         System.out.println("-- socket options --");
   140         AsynchronousServerSocketChannel ch = AsynchronousServerSocketChannel.open();
   140         AsynchronousServerSocketChannel ch = AsynchronousServerSocketChannel.open();
   141         try {
   141         try {
   142             // check supported options
   142             // check supported options
   143             Set<SocketOption<?>> options = ch.supportedOptions();
   143             Set<SocketOption<?>> options = ch.supportedOptions();
       
   144             boolean reuseport = options.contains(SO_REUSEPORT);
   144             if (!options.contains(SO_REUSEADDR))
   145             if (!options.contains(SO_REUSEADDR))
   145                 throw new RuntimeException("SO_REUSEADDR should be supported");
   146                 throw new RuntimeException("SO_REUSEADDR should be supported");
       
   147             if (!options.contains(SO_REUSEPORT) && reuseport)
       
   148                 throw new RuntimeException("SO_REUSEPORT should be supported");
   146             if (!options.contains(SO_RCVBUF))
   149             if (!options.contains(SO_RCVBUF))
   147                 throw new RuntimeException("SO_RCVBUF should be supported");
   150                 throw new RuntimeException("SO_RCVBUF should be supported");
   148 
   151 
   149             // allowed to change when not bound
   152             // allowed to change when not bound
   150             ch.setOption(SO_RCVBUF, 256*1024);     // can't check
   153             ch.setOption(SO_RCVBUF, 256*1024);     // can't check
   154                  throw new RuntimeException("setOption caused SO_RCVBUF to decrease");
   157                  throw new RuntimeException("setOption caused SO_RCVBUF to decrease");
   155             ch.setOption(SO_REUSEADDR, true);
   158             ch.setOption(SO_REUSEADDR, true);
   156             checkOption(ch, SO_REUSEADDR, true);
   159             checkOption(ch, SO_REUSEADDR, true);
   157             ch.setOption(SO_REUSEADDR, false);
   160             ch.setOption(SO_REUSEADDR, false);
   158             checkOption(ch, SO_REUSEADDR, false);
   161             checkOption(ch, SO_REUSEADDR, false);
       
   162 
       
   163             if (reuseport) {
       
   164                 ch.setOption(SO_REUSEPORT, true);
       
   165                 checkOption(ch, SO_REUSEPORT, true);
       
   166                 ch.setOption(SO_REUSEPORT, false);
       
   167                 checkOption(ch, SO_REUSEPORT, false);
       
   168             }
   159         } finally {
   169         } finally {
   160             ch.close();
   170             ch.close();
   161         }
   171         }
   162     }
   172     }
   163 
   173