author | aefimov |
Wed, 10 Jul 2019 16:09:20 +0100 | |
changeset 55645 | 3203e857fa71 |
parent 54811 | 9db7c0f561a6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55645
3203e857fa71
8226756: Replace wildcard address with loopback or local host in tests - part 18
aefimov
parents:
54811
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4508149 |
|
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
49431
diff
changeset
|
27 |
* @library /test/lib |
2 | 28 |
* @summary Setting ServerSocket.setSoTimeout shouldn't cause |
29 |
* the timeout to be inherited by accepted connections |
|
49431
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
30 |
* @run main InheritTimeout |
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
31 |
* @run main/othervm -Djava.net.preferIPv4Stack=true InheritTimeout |
2 | 32 |
*/ |
33 |
||
34 |
import java.net.*; |
|
35 |
import java.io.InputStream; |
|
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
49431
diff
changeset
|
36 |
import jdk.test.lib.net.IPSupport; |
2 | 37 |
|
38 |
public class InheritTimeout { |
|
39 |
||
40 |
class Reaper extends Thread { |
|
41 |
Socket s; |
|
42 |
int timeout; |
|
43 |
||
44 |
Reaper(Socket s, int timeout) { |
|
45 |
this.s = s; |
|
46 |
this.timeout = timeout; |
|
47 |
} |
|
48 |
||
49 |
public void run() { |
|
50 |
try { |
|
51 |
Thread.currentThread().sleep(timeout); |
|
52 |
s.close(); |
|
53 |
} catch (Exception e) { |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
InheritTimeout() throws Exception { |
|
55645
3203e857fa71
8226756: Replace wildcard address with loopback or local host in tests - part 18
aefimov
parents:
54811
diff
changeset
|
59 |
InetAddress ia = InetAddress.getLocalHost(); |
3203e857fa71
8226756: Replace wildcard address with loopback or local host in tests - part 18
aefimov
parents:
54811
diff
changeset
|
60 |
ServerSocket ss = new ServerSocket(); |
3203e857fa71
8226756: Replace wildcard address with loopback or local host in tests - part 18
aefimov
parents:
54811
diff
changeset
|
61 |
ss.bind(new InetSocketAddress(ia, 0)); |
2 | 62 |
ss.setSoTimeout(1000); |
63 |
||
64 |
InetSocketAddress isa = |
|
65 |
new InetSocketAddress(ia, ss.getLocalPort()); |
|
66 |
||
67 |
// client establishes the connection |
|
68 |
Socket s1 = new Socket(); |
|
69 |
s1.connect(isa); |
|
70 |
||
71 |
// receive the connection |
|
72 |
Socket s2 = ss.accept(); |
|
73 |
||
74 |
// schedule reaper to close the socket in 5 seconds |
|
75 |
Reaper r = new Reaper(s2, 5000); |
|
76 |
r.start(); |
|
77 |
||
78 |
boolean readTimedOut = false; |
|
79 |
try { |
|
80 |
s2.getInputStream().read(); |
|
81 |
} catch (SocketTimeoutException te) { |
|
82 |
readTimedOut = true; |
|
83 |
} catch (SocketException e) { |
|
84 |
if (!s2.isClosed()) { |
|
85 |
throw e; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
s1.close(); |
|
90 |
ss.close(); |
|
91 |
||
92 |
if (readTimedOut) { |
|
93 |
throw new Exception("Unexpected SocketTimeoutException throw!"); |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
public static void main(String args[]) throws Exception { |
|
54811
9db7c0f561a6
8223652: Rename IPSupport.skipIfCurrentConfigurationIsInvalid() to IPSupport.throwSkippedExceptionIfNonOperational()
aeubanks
parents:
54770
diff
changeset
|
98 |
IPSupport.throwSkippedExceptionIfNonOperational(); |
2 | 99 |
new InheritTimeout(); |
100 |
} |
|
101 |
} |