Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/net/Socket/FDClose.java
+++ new/test/java/net/Socket/FDClose.java
1 1 /*
2 2 * Copyright 1998-2002 Sun Microsystems, Inc. All Rights Reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
↓ 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
46 53 // wait for the server socket to be ready
↓ 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