[NREPL-13] nrepl should support binding to a specific interface instead of all Created: 29/Feb/12 Updated: 29/Mar/12 Resolved: 29/Mar/12 |
|
| Status: | Closed |
| Project: | tools.nrepl |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 0.2.0 |
| Type: | Enhancement | Priority: | Major |
| Reporter: | Toby Crawley | Assignee: | Chas Emerick |
| Resolution: | Completed | Votes: | 0 |
| Labels: | None | ||
| Patch: | Code |
| Description |
|
nrepl currently accepts a :port to bind to as an option, and uses that with the single-arg ServerSocket constructor, which binds to that port on all interfaces. I propose we add a :host option as well that can be used to specify the hostname or address of the interface to bind to. Here is a potential implementation: diff --git a/src/main/clojure/clojure/tools/nrepl/server.clj b/src/main/clojure/clojure/tools/nrepl/server.clj
index 9dbac40..b6f625b 100644
--- a/src/main/clojure/clojure/tools/nrepl/server.clj
+++ b/src/main/clojure/clojure/tools/nrepl/server.clj
@@ -8,7 +8,7 @@
pr-values
session))
(:use [clojure.tools.nrepl.misc :only (returning response-for log)])
- (:import (java.net Socket ServerSocket)))
+ (:import (java.net InetAddress Socket ServerSocket)))
(defn unknown-op
"Sends an :unknown-op :error for the given message."
@@ -64,7 +64,9 @@
(defn start-server
"Starts a socket-based nREPL server. Configuration options include:
-
+
+ * :host — the address or hostname of the interface that should be used;
+ defaults to all interfaces
* :port — defaults to 0, which autoselects an open port on localhost
* :handler — the nREPL message handler to use for each incoming connection;
defaults to the result of (default-handler)
@@ -77,8 +79,10 @@
Returns a handle to the server that is started, which may be stopped
either via `stop-server`, (.close server), or automatically via `with-open`."
- [& {:keys [port transport-fn handler ack-port greeting-fn] :or {port 0}}]
- (let [ss (ServerSocket. port)
+ [& {:keys [host port transport-fn handler ack-port greeting-fn] :or {port 0}}]
+ (let [ss (if host
+ (ServerSocket. port 0 (InetAddress/getByName host))
+ (ServerSocket. port))
smap {:ss ss
:transport (or transport-fn t/bencode)
:greeting greeting-fn
I'm putting a CA in the mail today. |
| Comments |
| Comment by Chas Emerick [ 29/Mar/12 12:53 PM ] |
|
Fixed on master, released as part of 0.2.0-beta3. |