staticvoid startTest() {
ServerSocket ss; int port;
Process process;
// create a ServerSocket listening on any port try {
ss = new ServerSocket(0);
port = ss.getLocalPort();
System.out.println("First ServerSocket listening on port " + port);
} catch (IOException e) {
System.out.println("Cannot create ServerSocket");
e.printStackTrace(); return;
}
// create another java process that simply waits. If the bug is present this // process will inherit the native IPv6 handle for ss and cause the second // ServerSocket constructor to throw a BindException try {
process = Runtime.getRuntime().exec(java + " InheritHandle -doWait");
} catch (IOException ioe) {
System.out.println("Cannot create process");
ioe.printStackTrace(); try {
ss.close();
} catch (IOException e) {
e.printStackTrace();
} return;
}
// Allow some time for the process to get started try {
System.out.println("waiting..."); Thread.sleep(2 * 1000);
System.out.println("Now close the socket and try to create another" + " one listening on the same port");
ss.close(); int retries = 0; while (retries < 5) { try (ServerSocket s = new ServerSocket(port);) {
System.out.println("Second ServerSocket created successfully"); break;
} catch (BindException e) {
System.out.println("BindException \"" + e.getMessage() + "\", retrying..."); Thread.sleep(100L);
retries ++; 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.