-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbind-address.patch
More file actions
65 lines (61 loc) · 3.03 KB
/
Copy pathbind-address.patch
File metadata and controls
65 lines (61 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From a97603787acc1430b7e129ec3da9dea9b549efb0 Mon Sep 17 00:00:00 2001
From: lhchavez <lhchavez@lhchavez.com>
Date: Tue, 8 Jun 2021 17:03:38 +0000
Subject: [PATCH] Add a System property to allow binding to a specific
interface/port
This change adds support to read the value of the
`com.microsoft.java.debug.serverAddress` system property when
constructing the JavaDebugServer. This allows callers to specify a
specific interface to bind to (e.g. `localhost:0`), a specific port
(e.g. `:12345`), or both (e.g. `localhost:12345`).
---
.../plugin/internal/JavaDebugServer.java | 29 ++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
index 32ab195b..12c2955c 100644
--- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
+++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
@@ -12,8 +12,10 @@
package com.microsoft.java.debug.plugin.internal;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.net.UnknownHostException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -33,8 +35,33 @@
private ExecutorService executor = null;
private JavaDebugServer() {
+ int port = 0;
+ InetAddress bindAddr = null;
+ String serverAddress = System.getProperty("com.microsoft.java.debug.serverAddress");
+ if (serverAddress != null) {
+ int portIndex = serverAddress.lastIndexOf(':');
+ if (portIndex == -1) {
+ logger.log(Level.SEVERE, String.format("Malformed server address \"%s\": missing port", serverAddress));
+ return;
+ }
+ try {
+ port = Integer.parseInt(serverAddress.substring(portIndex + 1));
+ } catch (NumberFormatException e) {
+ logger.log(Level.SEVERE, String.format("Malformed server address \"%s\": %s", serverAddress, e.toString()), e);
+ return;
+ }
+
+ if (portIndex > 0) {
+ try {
+ bindAddr = InetAddress.getByName(serverAddress.substring(0, portIndex));
+ } catch (UnknownHostException e) {
+ logger.log(Level.SEVERE, String.format("Invalid server address \"%s\": %s", serverAddress, e.toString()), e);
+ return;
+ }
+ }
+ }
try {
- this.serverSocket = new ServerSocket(0, 1);
+ this.serverSocket = new ServerSocket(port, 1, bindAddr);
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("Failed to create Java Debug Server: %s", e.toString()), e);
}