author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58313 | 8a2bc12d2a9a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58313
8a2bc12d2a9a
8231450: Copyright header line omitted from 8231187 changeset
michaelm
parents:
58295
diff
changeset
|
2 |
* Copyright (c) 2003, 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 |
* A Launcher to launch a java process with its standard input, output, |
|
26 |
* and error streams connected to a socket. |
|
27 |
*/ |
|
28 |
import java.io.IOException; |
|
45578
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
29 |
import java.net.InetAddress; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
30 |
import java.net.InetSocketAddress; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
31 |
import java.nio.channels.DatagramChannel; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
32 |
import java.nio.channels.ServerSocketChannel; |
cd8f28842351
8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
amlu
parents:
23041
diff
changeset
|
33 |
import java.nio.channels.SocketChannel; |
2 | 34 |
|
35 |
public class Launcher { |
|
36 |
||
37 |
static { |
|
49128
97288886180c
8198834: (ch) Enable java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java on linux-x64
bpb
parents:
47216
diff
changeset
|
38 |
System.loadLibrary("InheritedChannel"); |
2 | 39 |
} |
40 |
||
41 |
private static native void launch0(String cmdarray[], int fd) throws IOException; |
|
42 |
||
43 |
private static void launch(String className, String options[], String args[], int fd) throws IOException { |
|
44 |
// java [-options] class [args...] |
|
23041
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
45 |
int optsLen = (options == null) ? 0 : options.length; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
46 |
int argsLen = (args == null) ? 0 : args.length; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
47 |
int len = 1 + optsLen + 1 + argsLen; |
2 | 48 |
String cmdarray[] = new String[len]; |
49 |
int pos = 0; |
|
23041
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
50 |
cmdarray[pos++] = Util.javaCommand(); |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
51 |
if (options != null) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
52 |
for (String opt: options) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
53 |
cmdarray[pos++] = opt; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
54 |
} |
2 | 55 |
} |
56 |
cmdarray[pos++] = className; |
|
23041
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
57 |
if (args != null) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
58 |
for (String arg: args) { |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
59 |
cmdarray[pos++] = arg; |
1aa7ce9cd0f1
8010194: java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh fails with "Timed out waiting ..." (sol)
alanb
parents:
23010
diff
changeset
|
60 |
} |
2 | 61 |
} |
62 |
launch0(cmdarray, fd); |
|
63 |
} |
|
64 |
||
52778
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
65 |
|
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
66 |
/** |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
67 |
* Launch 'java' with specified class using a UnixDomainSocket pair linking calling |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
68 |
* process to the child VM. UnixDomainSocket is a simplified interface to PF_UNIX sockets |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
69 |
* which supports byte a time reads and writes. |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
70 |
*/ |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
71 |
public static UnixDomainSocket launchWithUnixDomainSocket(String className) throws IOException { |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
72 |
UnixDomainSocket[] socks = UnixDomainSocket.socketpair(); |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
73 |
launch(className, null, null, socks[0].fd()); |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
74 |
socks[0].close(); |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
75 |
return socks[1]; |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
76 |
} |
dbbf46b13d52
8211842: IPv6_supported wrongly returns false when unix domain socket is bound to fd 0
michaelm
parents:
49128
diff
changeset
|
77 |
|
58295
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
78 |
/** |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
79 |
* Launch specified class with an AF_UNIX socket created externally, and one String arg to child VM |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
80 |
*/ |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
81 |
public static void launchWithUnixDomainSocket(String className, UnixDomainSocket socket, String arg) throws IOException { |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
82 |
String[] args = new String[1]; |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
83 |
args[0] = arg; |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
84 |
launch(className, null, args, socket.fd()); |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
85 |
} |
7973073dd048
8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents:
52778
diff
changeset
|
86 |
|
2 | 87 |
/* |
88 |
* Launch 'java' with specified class with the specified arguments (may be null). |
|
89 |
* The launched process will inherit a connected TCP socket. The remote endpoint |
|
90 |
* will be the SocketChannel returned by this method. |
|
91 |
*/ |
|
92 |
public static SocketChannel launchWithSocketChannel(String className, String options[], String args[]) throws IOException { |
|
93 |
ServerSocketChannel ssc = ServerSocketChannel.open(); |
|
94 |
ssc.socket().bind(new InetSocketAddress(0)); |
|
95 |
InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), |
|
96 |
ssc.socket().getLocalPort()); |
|
97 |
SocketChannel sc1 = SocketChannel.open(isa); |
|
98 |
SocketChannel sc2 = ssc.accept(); |
|
99 |
launch(className, options, args, Util.getFD(sc2)); |
|
100 |
sc2.close(); |
|
101 |
ssc.close(); |
|
102 |
return sc1; |
|
103 |
} |
|
104 |
||
105 |
public static SocketChannel launchWithSocketChannel(String className, String args[]) throws IOException { |
|
106 |
return launchWithSocketChannel(className, null, args); |
|
107 |
} |
|
108 |
||
109 |
public static SocketChannel launchWithSocketChannel(String className) throws IOException { |
|
110 |
return launchWithSocketChannel(className, null); |
|
111 |
} |
|
112 |
||
113 |
/* |
|
114 |
* Launch 'java' with specified class with the specified arguments (may be null). |
|
115 |
* The launched process will inherited a TCP listener socket. |
|
116 |
* Once launched this method tries to connect to service. If a connection |
|
117 |
* can be established a SocketChannel, connected to the service, is returned. |
|
118 |
*/ |
|
119 |
public static SocketChannel launchWithServerSocketChannel(String className, String options[], String args[]) |
|
120 |
throws IOException |
|
121 |
{ |
|
122 |
ServerSocketChannel ssc = ServerSocketChannel.open(); |
|
123 |
ssc.socket().bind(new InetSocketAddress(0)); |
|
124 |
int port = ssc.socket().getLocalPort(); |
|
125 |
launch(className, options, args, Util.getFD(ssc)); |
|
126 |
ssc.close(); |
|
127 |
InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), port); |
|
128 |
return SocketChannel.open(isa); |
|
129 |
} |
|
130 |
||
131 |
public static SocketChannel launchWithServerSocketChannel(String className, String args[]) throws IOException { |
|
132 |
return launchWithServerSocketChannel(className, null, args); |
|
133 |
} |
|
134 |
||
135 |
public static SocketChannel launchWithServerSocketChannel(String className) throws IOException { |
|
136 |
return launchWithServerSocketChannel(className, null); |
|
137 |
} |
|
138 |
||
139 |
/* |
|
140 |
* Launch 'java' with specified class with the specified arguments (may be null). |
|
141 |
* The launch process will inherited a bound UDP socket. |
|
142 |
* Once launched this method creates a DatagramChannel and "connects |
|
143 |
* it to the service. The created DatagramChannel is then returned. |
|
144 |
* As it is connected any packets sent from the socket will be |
|
145 |
* sent to the service. |
|
146 |
*/ |
|
147 |
public static DatagramChannel launchWithDatagramChannel(String className, String options[], String args[]) |
|
148 |
throws IOException |
|
149 |
{ |
|
150 |
DatagramChannel dc = DatagramChannel.open(); |
|
151 |
dc.socket().bind(new InetSocketAddress(0)); |
|
152 |
||
153 |
int port = dc.socket().getLocalPort(); |
|
154 |
launch(className, options, args, Util.getFD(dc)); |
|
155 |
dc.close(); |
|
156 |
||
157 |
dc = DatagramChannel.open(); |
|
16480
fcad3b6ec812
7183800: TEST_BUG: Update tests to run on Ubuntu 12.04 (localhost is 127.0.1.1)
alanb
parents:
5506
diff
changeset
|
158 |
InetAddress address = InetAddress.getLocalHost(); |
fcad3b6ec812
7183800: TEST_BUG: Update tests to run on Ubuntu 12.04 (localhost is 127.0.1.1)
alanb
parents:
5506
diff
changeset
|
159 |
if (address.isLoopbackAddress()) { |
fcad3b6ec812
7183800: TEST_BUG: Update tests to run on Ubuntu 12.04 (localhost is 127.0.1.1)
alanb
parents:
5506
diff
changeset
|
160 |
address = InetAddress.getLoopbackAddress(); |
fcad3b6ec812
7183800: TEST_BUG: Update tests to run on Ubuntu 12.04 (localhost is 127.0.1.1)
alanb
parents:
5506
diff
changeset
|
161 |
} |
fcad3b6ec812
7183800: TEST_BUG: Update tests to run on Ubuntu 12.04 (localhost is 127.0.1.1)
alanb
parents:
5506
diff
changeset
|
162 |
InetSocketAddress isa = new InetSocketAddress(address, port); |
2 | 163 |
|
164 |
dc.connect(isa); |
|
165 |
return dc; |
|
166 |
} |
|
167 |
||
168 |
public static DatagramChannel launchWithDatagramChannel(String className, String args[]) throws IOException { |
|
169 |
return launchWithDatagramChannel(className, null, args); |
|
170 |
} |
|
171 |
||
172 |
public static DatagramChannel launchWithDatagramChannel(String className) throws IOException { |
|
173 |
return launchWithDatagramChannel(className, null); |
|
174 |
} |
|
175 |
} |