以下代码用于{{src/clj/clojure/core/server.clj}}验证端口号是否有效
(defn- validate-opts "验证服务器配置选项" [{:keys [name port accept] :as opts}] (doseq [prop [:name :port :accept]] (required opts prop)) (when (or (not (integer? port)) (not (< -1 port 65535))) (throw (ex-info (str "无效的套接字服务器端口号: " port) opts))))
但这有一个非常小的错误,因为排除端口65535,但实际上它是一个有效的端口。
`
user=> (defn is-invalid-port [port] (or (not (integer? port)) (not (< -1 port 65535))))
'user/is-invalid-port
user=> (is-invalid-port 65534)
false
user=> (is-invalid-port 65535) ; 应该是false!
true
user=> (is-invalid-port 65536)
true
`
这由(链接:https://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html#ServerSocket(int))佐证
{引用}
IllegalArgumentException - 如果端口号参数超出了指定的有效端口号范围,范围为0和65535,包含端点号。
{引用}
补丁: port-65535-obo-v2.patch
预审: Alex Miller