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 * @summary test to see if interrupting a socket accept closes fd0 28 */ 29 import java.net.*; 30 import java.io.*; 31 import java.util.*; 32 33 public class FDClose { 34 35 static boolean isServerReady = false; 36 37 public static void main(String[] args) throws Exception { 38 39 Thread me = Thread.currentThread(); 40 41 // Put a thread waiting on SocketServer.Accept 42 AReader test = new AReader(); 43 Thread readerThread = new Thread(test); 44 readerThread.start(); 45 46 // wait for the server socket to be ready 47 while (!isServerReady) { 48 me.sleep(100); 49 } 50 51 // Interrupt the waiting thread 52 readerThread.interrupt(); 53 54 // Wait another moment 55 me.sleep(100); 56 57 // Check to see if fd0 is closed 58 System.in.available(); 59 } 60 61 public static class AReader implements Runnable { 62 public void run() { 63 try { 64 ServerSocket sock = new ServerSocket(0); 65 isServerReady = true; 66 sock.accept(); 67 } catch (Exception e) { 68 } 69 } 70 } 71 } --- EOF ---