equal
deleted
inserted
replaced
24 /* |
24 /* |
25 * author Edward Wang |
25 * author Edward Wang |
26 * |
26 * |
27 * @test |
27 * @test |
28 * @bug 6368984 |
28 * @bug 6368984 |
|
29 * @key intermittent |
29 * @summary Configuring unconnected Socket before passing to implAccept |
30 * @summary Configuring unconnected Socket before passing to implAccept |
30 * can cause fd leak |
31 * can cause fd leak. |
|
32 * This test may fail intermittently if foreign processes will |
|
33 * try to establish connection to the test server socket. |
31 * @requires (os.family != "windows") |
34 * @requires (os.family != "windows") |
32 * @library /test/lib |
35 * @library /test/lib |
33 * @build jdk.test.lib.Utils |
36 * @build jdk.test.lib.Utils |
34 * jdk.test.lib.Asserts |
37 * jdk.test.lib.Asserts |
35 * jdk.test.lib.JDKToolFinder |
38 * jdk.test.lib.JDKToolFinder |
41 * @run main/othervm -Djdk.net.usePlainSocketImpl AcceptCauseFileDescriptorLeak root |
44 * @run main/othervm -Djdk.net.usePlainSocketImpl AcceptCauseFileDescriptorLeak root |
42 */ |
45 */ |
43 |
46 |
44 import java.io.IOException; |
47 import java.io.IOException; |
45 import java.net.InetAddress; |
48 import java.net.InetAddress; |
|
49 import java.net.InetSocketAddress; |
46 import java.net.ServerSocket; |
50 import java.net.ServerSocket; |
47 import java.net.Socket; |
51 import java.net.Socket; |
48 import java.util.List; |
52 import java.util.List; |
49 |
53 |
50 import jdk.test.lib.JDKToolFinder; |
54 import jdk.test.lib.JDKToolFinder; |
80 return; |
84 return; |
81 } |
85 } |
82 } |
86 } |
83 } |
87 } |
84 |
88 |
85 final ServerSocket ss = new ServerSocket(0, 0, InetAddress.getLoopbackAddress()) { |
89 final ServerSocket ss = new ServerSocket() { |
86 public Socket accept() throws IOException { |
90 public Socket accept() throws IOException { |
87 Socket s = new Socket() { |
91 Socket s = new Socket() { |
88 }; |
92 }; |
89 s.setSoTimeout(10000); |
93 s.setSoTimeout(10000); |
90 implAccept(s); |
94 implAccept(s); |
91 return s; |
95 return s; |
92 } |
96 } |
93 }; |
97 }; |
|
98 ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); |
94 Thread t = new Thread(new Runnable() { |
99 Thread t = new Thread(new Runnable() { |
95 public void run() { |
100 public void run() { |
|
101 int repsCompleted = 0; |
96 try { |
102 try { |
97 for (int i = 0; i < REPS; i++) { |
103 for (; repsCompleted < REPS; repsCompleted++) { |
98 (new Socket(InetAddress.getLoopbackAddress(), ss.getLocalPort())).close(); |
104 (new Socket(InetAddress.getLoopbackAddress(), ss.getLocalPort())).close(); |
99 } |
105 } |
100 } catch (IOException e) { |
106 } catch (IOException e) { |
101 e.printStackTrace(); |
107 e.printStackTrace(); |
|
108 } finally { |
|
109 System.out.println("Client iterations completed:" + repsCompleted); |
102 } |
110 } |
103 } |
111 } |
104 }); |
112 }); |
105 t.start(); |
113 t.start(); |
|
114 int repsCompleted = 0; |
106 try { |
115 try { |
107 for (int i = 0; i < REPS; i++) { |
116 for (; repsCompleted < REPS; repsCompleted++) { |
108 ss.accept().close(); |
117 ss.accept().close(); |
109 } |
118 } |
110 } finally { |
119 } finally { |
|
120 System.out.println("Server iterations completed:" + repsCompleted); |
111 ss.close(); |
121 ss.close(); |
112 } |
122 } |
113 t.join(); |
123 t.join(); |
114 } |
124 } |
115 |
125 |