I am pleased to announce that my first Clojure library is out!
With this lib I tried to embrace the concept of Clojure (composability, separation of concerns), so it does one things: Get an available TCP port with some options.
It also allowed me to experiment with setting up tests, deploying on Clojars with tools.deps, etc.
The experience was great.
;; - start a Socket REPL on an available port, and display that port:
;; - specify -r as well if you want a repl
:socket-zero {:jvm-opts ["-Dclojure.server.repl={:port,0,:accept,clojure.core.server/repl}"]
:main-opts ["-e" "(.getLocalPort,(get-in,@#'clojure.core.server/servers,[\"repl\",:socket]))"]}
This is really nice, but one small issue: Passing an argument like {:port 80} throws if it can’t assign that port, due to the (next port) form on line 31: Don't know how to create ISeq from: java.lang.Long.
No I was not aware of that, although I should have guessed it since this is operating system level behavior. At least for Unix OS.
So thanks for the information!
Knowing this, I guess it will allow me to simplify my library.
I am planning a fallback system for the next version.
In this way we can specify a port in the reserved range (tcp 80, 443 for eg.) and fallback to a random one if a “permission denied” error on a development machine for example.