From a007211e293d2316ad543b456457b7ac2703f59a Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 14 Feb 2024 14:51:15 +0100 Subject: [PATCH] feat: add support for port detection --- src/build/run.cr | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/build/run.cr b/src/build/run.cr index 0bbf523..f95591c 100644 --- a/src/build/run.cr +++ b/src/build/run.cr @@ -1,6 +1,7 @@ require "path" require "file_utils" +require "socket" require "./module" require "./config" @@ -38,7 +39,12 @@ module DocMachine::Build end private def _port_available?(port) - true + sock = Socket.new(Socket::Family::INET, Socket::Type::STREAM) + sock.bind(Socket::IPAddress.new("0.0.0.0", port)) + sock.close + return true + rescue ex : Socket::BindError + return false end private def _avoid_duplicates