1 /* 2 * Copyright 1998-2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24 /** 25 * @test 26 * @bug 4152799 27 * @run main/othervm -XX:+UseVMInterruptibleIO FDClose 28 * @summary test to see if interrupting a socket accept closes fd0 29 */ 30 31 /* This test requires interruptible I/O to verify that the accept 32 * implementation does not impact on fd0. UseVMInterruptibleIO needs to 33 * be explicitly enabled since it is now disabled by default, see 6554406 34 */ 35 36 import java.net.*; 37 import java.io.*; 38 import java.util.*; 39 40 public class FDClose { 41 42 static volatile boolean isServerReady = false; 43 44 public static void main(String[] args) throws Exception { 45 46 Thread me = Thread.currentThread(); 47 48 // Put a thread waiting on SocketServer.Accept 49 AReader test = new AReader(); 50 Thread readerThread = new Thread(test); 51 readerThread.start(); 52 53 // wait for the server socket to be ready 54 while (!isServerReady) { 55 me.sleep(100); 56 } 57 58 // Interrupt the waiting thread 59 readerThread.interrupt(); 60 61 // Wait another moment 62 me.sleep(100); 63 64 try { 65 // Check to see if fd0 is closed 66 System.in.available(); 67 } finally { 68 test.terminate(); 69 } 70 } 71 72 public static class AReader implements Runnable { 73 volatile ServerSocket sock; 74 75 public void run() { 76 try { 77 sock = new ServerSocket(0); 78 isServerReady = true; 79 sock.accept(); 80 } catch (Exception e) { 81 } 82 } 83 84 void terminate() { 85 try { 86 if (sock != null) sock.close(); 87 } catch (IOException e) {} 88 } 89 } 90 } --- EOF ---