fix(wren-launcher): fix checking port used (#82)

This commit is contained in:
william chang(張仲威)
2024-04-08 14:25:33 +08:00
committed by GitHub
parent efc7a2f675
commit 2428c2d2fa
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"github.com/pterm/pterm"
)
func ifPortAvailable(port int) bool {
func ifPortUsed(port int) bool {
// listen on port to check if it's used
_, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
return err != nil
@@ -20,7 +20,7 @@ func FindAvailablePort(defaultPort int) int {
for port := defaultPort; port < defaultPort+100; port++ {
pterm.Info.Printf("Checking if port %d is available\n", port)
if ifPortAvailable(port) {
if !ifPortUsed(port) {
// Return the port if it's not used
return port
} else if IfPortUsedByWrenUI(port) {