Skip to content

Commit

Permalink
Change net.Listen to net.Dial for checking port
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Nascimento committed Jun 24, 2023
1 parent 64a5b9d commit d7caa8a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ var LocalFlag bool

func checkPortAvailability(port int) bool {
address := fmt.Sprintf("localhost:%d", port)
listener, err := net.Listen("tcp", address)
conn, err := net.Dial("tcp", address)

if err == nil {
return false // Port is already in use
if err != nil {
return true // Port is available
}
defer listener.Close()
defer conn.Close()

return true // Port is available
return false // Port is already in use
}

func setPort(siteConfig readers.SiteConfig) int {
Expand Down

0 comments on commit d7caa8a

Please sign in to comment.