Codebase list kitchensink-clojure / 524ed14
New upstream version 3.1.1 Louis-Philippe VĂ©ronneau 3 years ago
2 changed file(s) with 10 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
0 (defproject puppetlabs/kitchensink "3.1.0"
0 (defproject puppetlabs/kitchensink "3.1.1"
11 :description "Clojure utility functions"
22 :license {:name "Apache License, Version 2.0"
33 :url "http://www.apache.org/licenses/LICENSE-2.0.html"}
10981098 (throw e)))))
10991099
11001100 (defn open-port-num
1101 "Returns a currently open port number in the traditional ephemeral port range
1102 of 49152 through 65535."
1101 "Returns a currently open port number in the port range 16384
1102 through 32767. Note that on Linux, anything above 32767 lies in
1103 the ephemeral port range, which is the range that the system uses
1104 to allocate ports upon user request. Thus, we choose from a
1105 different range to prevent possible port conflicts caused by
1106 various services (e.g. database connection pools)."
11031107 []
1104 (let [lo 49152
1105 hi 65536] ; one higher because the upper limit is exclusive
1108 (let [lo 16384
1109 hi 32768] ; one higher because the upper limit is exclusive
11061110 (if-let [open-port (some port-open? (shuffle (range lo hi)))]
11071111 open-port
11081112 (throw (java.net.BindException.
1109 "All ephemeral ports are already in use (Bind failed)")))))
1113 (format "All ports in the range %d through %d are already in use (Bind failed)" lo (dec hi)))))))
11101114
11111115 (defmacro assoc-if-new
11121116 "Assocs the provided values with the corresponding keys if and only