Path: blob/master/test/jdk/java/net/ServerSocket/AnotherSelectFdsLimit.java
41152 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803589726* @summary FD_SETSIZE should be set on macosx27* @run main/othervm AnotherSelectFdsLimit 102328* @run main/othervm AnotherSelectFdsLimit 102429* @run main/othervm AnotherSelectFdsLimit 102530* @run main/othervm AnotherSelectFdsLimit 160031*/3233import java.io.IOException;34import java.net.ServerSocket;35import java.net.SocketTimeoutException;36import java.util.ArrayList;37import java.util.List;3839public class AnotherSelectFdsLimit {40static final int DEFAULT_FDS_TO_USE = 1600;4142public static void main(String [] args) throws Exception {43if (!System.getProperty("os.name").contains("OS X")) {44System.out.println("Test only run on MAC. Exiting.");45return;46}4748int fdsToUse = DEFAULT_FDS_TO_USE;49if (args.length == 1)50fdsToUse = Integer.parseInt(args[0]);5152System.out.println("Using " + fdsToUse + " fds.");5354List<Thread> threads = new ArrayList<>();55for (int i=0; i<fdsToUse; i++)56threads.add(new WorkerThread());5758for (Thread t : threads)59t.start();6061for (Thread t : threads)62t.join();63}6465static class WorkerThread extends Thread {66public void run() {67try (ServerSocket ss = new ServerSocket(0)) {68ss.setSoTimeout(2000);69ss.accept();70} catch (SocketTimeoutException x) {71// expected72} catch (IOException x) {73throw new java.io.UncheckedIOException(x);74}75}76}77}787980