test/java/nio/channels/Selector/Alias.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 25,59 **** * @bug 4513011 * @summary Registering and cancelling same fd many times * @library .. */ - import java.io.*; import java.net.*; import java.nio.*; import java.nio.channels.*; - import java.util.*; import java.nio.channels.spi.SelectorProvider; public class Alias { static int success = 0; static int LIMIT = 20; // Hangs after just 1 if problem is present public static void main(String[] args) throws Exception { ! test1(); } ! public static void test1() throws Exception { Selector selector = SelectorProvider.provider().openSelector(); ! InetAddress myAddress=InetAddress.getByName(TestUtil.HOST); ! InetSocketAddress isa = new InetSocketAddress(myAddress,13); for (int j=0; j<LIMIT; j++) { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); boolean result = sc.connect(isa); if (!result) { SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT); while (!result) { int keysAdded = selector.select(100); --- 25,66 ---- * @bug 4513011 * @summary Registering and cancelling same fd many times * @library .. */ import java.net.*; import java.nio.*; import java.nio.channels.*; import java.nio.channels.spi.SelectorProvider; + import java.util.*; public class Alias { static int success = 0; static int LIMIT = 20; // Hangs after just 1 if problem is present public static void main(String[] args) throws Exception { ! try (TestClass.DayTimeServer daytimeServer ! = TestClass.DayTimeServer.startNewServer(100)) { ! test1(daytimeServer); ! } } ! static void test1(TestClass.DayTimeServer daytimeServer) throws Exception { Selector selector = SelectorProvider.provider().openSelector(); ! InetAddress myAddress = daytimeServer.getAddress(); ! InetSocketAddress isa ! = new InetSocketAddress(myAddress, ! daytimeServer.getPort()); for (int j=0; j<LIMIT; j++) { SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); boolean result = sc.connect(isa); + + // On some platforms - given that we're using a local server, + // we may not enter into the if () { } statement below... if (!result) { SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT); while (!result) { int keysAdded = selector.select(100);