test/java/net/Socket/FDClose.java

Print this page

        

*** 22,40 **** */ /** * @test * @bug 4152799 * @summary test to see if interrupting a socket accept closes fd0 */ import java.net.*; import java.io.*; import java.util.*; public class FDClose { ! static boolean isServerReady = false; public static void main(String[] args) throws Exception { Thread me = Thread.currentThread(); --- 22,47 ---- */ /** * @test * @bug 4152799 + * @run main/othervm -XX:+UseVMInterruptibleIO FDClose * @summary test to see if interrupting a socket accept closes fd0 */ + + /* This test requires interruptible I/O to verify that the accept + * implementation does not impact on fd0. UseVMInterruptibleIO needs to + * be explicitly enabled since it is now disabled by default, see 6554406 + */ + import java.net.*; import java.io.*; import java.util.*; public class FDClose { ! static volatile boolean isServerReady = false; public static void main(String[] args) throws Exception { Thread me = Thread.currentThread();
*** 52,71 **** readerThread.interrupt(); // Wait another moment me.sleep(100); // Check to see if fd0 is closed System.in.available(); } public static class AReader implements Runnable { public void run() { try { ! ServerSocket sock = new ServerSocket(0); isServerReady = true; sock.accept(); } catch (Exception e) { } } } } --- 59,90 ---- readerThread.interrupt(); // Wait another moment me.sleep(100); + try { // Check to see if fd0 is closed System.in.available(); + } finally { + test.terminate(); } + } public static class AReader implements Runnable { + volatile ServerSocket sock; + public void run() { try { ! sock = new ServerSocket(0); isServerReady = true; sock.accept(); } catch (Exception e) { } } + + void terminate() { + try { + if (sock != null) sock.close(); + } catch (IOException e) {} } + } }