Print this page


Split Close
Expand all
Collapse all
          --- old/test/java/net/Socket/FDClose.java
          +++ new/test/java/net/Socket/FDClose.java
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18   18   *
  19   19   * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20   20   * CA 95054 USA or visit www.sun.com if you need additional information or
  21   21   * have any questions.
  22   22   */
  23   23  
  24   24  /**
  25   25   * @test
  26   26   * @bug 4152799
       27 + * @run main/othervm -XX:+UseVMInterruptibleIO FDClose
  27   28   * @summary  test to see if interrupting a socket accept closes fd0
  28   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 +
  29   36  import java.net.*;
  30   37  import java.io.*;
  31   38  import java.util.*;
  32   39  
  33   40  public class FDClose {
  34   41  
  35      -    static boolean isServerReady = false;
       42 +    static volatile boolean isServerReady = false;
  36   43  
  37   44      public static void main(String[] args) throws Exception {
  38   45  
  39   46          Thread me = Thread.currentThread();
  40   47  
  41   48          // Put a thread waiting on SocketServer.Accept
  42   49          AReader test = new AReader();
  43   50          Thread readerThread = new Thread(test);
  44   51          readerThread.start();
  45   52  
↓ open down ↓ 1 lines elided ↑ open up ↑
  47   54          while (!isServerReady) {
  48   55              me.sleep(100);
  49   56          }
  50   57  
  51   58          // Interrupt the waiting thread
  52   59          readerThread.interrupt();
  53   60  
  54   61          // Wait another moment
  55   62          me.sleep(100);
  56   63  
  57      -        // Check to see if fd0 is closed
  58      -        System.in.available();
       64 +        try {
       65 +            // Check to see if fd0 is closed
       66 +            System.in.available();
       67 +        } finally {
       68 +           test.terminate();
       69 +        }
  59   70      }
  60   71  
  61   72      public static class AReader implements Runnable {
       73 +        volatile ServerSocket sock;
       74 +
  62   75          public void run() {
  63   76              try {
  64      -                ServerSocket sock = new ServerSocket(0);
       77 +                sock = new ServerSocket(0);
  65   78                  isServerReady = true;
  66   79                  sock.accept();
  67   80              } catch (Exception e) {
  68   81              }
  69   82          }
       83 +
       84 +        void terminate() {
       85 +            try {
       86 +                if (sock != null) sock.close();
       87 +            } catch (IOException e) {}
       88 +        }
  70   89      }
  71   90  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX