/* * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 4417734 * @key intermittent * @summary Test that we get a BindException in all expected combinations * @library /test/lib * @build jdk.test.lib.NetworkConfiguration * jdk.test.lib.Platform * @run main Test -d
*/
if (s1_type.equals("Socket")) {
sock1 = new Socket();
sock1.bind( new InetSocketAddress(ia1, 0));
port = sock1.getLocalPort();
}
if (s1_type.equals("ServerSocket")) {
ss = new ServerSocket(0, 0, ia1);
port = ss.getLocalPort();
}
if (s1_type.equals("DatagramSocket")) {
dsock1 = new DatagramSocket( new InetSocketAddress(ia1, 0) );
port = dsock1.getLocalPort();
}
/* bind the second socket */
// The fact that the port was available for ia1 does not // guarantee that it will also be available for ia2 as something // else might already be bound to that port. // For the sake of test stability we will retry once in // case of unexpected bind exception.
firstBound = true; if (s2_type.equals("Socket")) { try (Socket sock2 = new Socket()) {
sock2.bind( new InetSocketAddress(ia2, port));
}
}
if (s2_type.equals("ServerSocket")) { try (ServerSocket ss2 = new ServerSocket(port, 0, ia2)) { }
}
if (s2_type.equals("DatagramSocket")) { try (DatagramSocket ds = new DatagramSocket(new InetSocketAddress(ia2, port))) { }
}
boolean silent = true; if (args.length > 0) { if (args[0].equals("-d")) {
silent = false;
}
}
/* * Test needs an IPv4 and IPv6 address to run.
*/
Enumeration nifs = NetworkInterface.getNetworkInterfaces(); while (nifs.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface)nifs.nextElement();
Enumeration addrs = ni.getInetAddresses(); while (addrs.hasMoreElements()) {
InetAddress ia = (InetAddress)addrs.nextElement();
if (ia.isLoopbackAddress() || ia.isAnyLocalAddress()) { continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.