< prev index next >

src/share/classes/com/sun/tools/jdi/SocketListeningConnector.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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.  Oracle designates this

@@ -27,10 +27,11 @@
 import com.sun.jdi.connect.*;
 import com.sun.jdi.connect.spi.*;
 import java.util.Map;
 import java.util.HashMap;
 import java.io.IOException;
+import com.sun.jdi.connect.spi.TransportService;
 
 /*
  * An ListeningConnector that uses the SocketTransportService
  */
 public class SocketListeningConnector extends GenericListeningConnector {

@@ -90,6 +91,23 @@
     }
 
     public String description() {
         return getString("socket_listening.description");
     }
+
+    // If the port is auto detected update the argument map with the bound port number.
+    @Override
+    protected void updateArgumentMapIfRequired(
+        Map<String, ? extends Connector.Argument> args, TransportService.ListenKey listener) {
+        if (isWildcardPort(args)) {
+            String[] address = listener.address().split(":");
+            if (address.length > 1) {
+                args.get(ARG_PORT).setValue(address[1]);
+            }
+        }
+    }
+
+    private boolean isWildcardPort(Map<String, ? extends Connector.Argument> args) {
+        String port = args.get(ARG_PORT).value();
+        return port.isEmpty() || Integer.valueOf(port) == 0;
+    }
 }
< prev index next >