Uploaded image for project: 'tools.nrepl'
  1. NREPL-13

nrepl should support binding to a specific interface instead of all

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: None
    • Fix versions: 0.2.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.

        Attachments

          Activity

            People

            • Assignee:
              cemerick Chas Emerick
              Reporter:
              tcrawley tcrawley
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: