MCPcopy Index your code
hub / github.com/jetify-com/devbox / selectPort

Function selectPort

internal/services/ports.go:60–77  ·  view source on GitHub ↗
(configPort int)

Source from the content-addressed store, hash-verified

58}
59
60func selectPort(configPort int) (int, error) {
61 if configPort != 0 {
62 return isPortAvailable(configPort)
63 }
64
65 if portStr, exists := os.LookupEnv("DEVBOX_PC_PORT_NUM"); exists {
66 port, err := strconv.Atoi(portStr)
67 if err != nil {
68 return 0, fmt.Errorf("invalid DEVBOX_PC_PORT_NUM environment variable: %v", err)
69 }
70 if port <= 0 {
71 return 0, fmt.Errorf("invalid DEVBOX_PC_PORT_NUM environment variable: ports cannot be less than 0")
72 }
73 return isPortAvailable(port)
74 }
75
76 return getAvailablePort()
77}
78
79func isAllowed(port int) bool {
80 return port > 1024 && disallowedPorts[port] == ""

Callers 1

StartProcessManagerFunction · 0.85

Calls 2

isPortAvailableFunction · 0.85
getAvailablePortFunction · 0.85

Tested by

no test coverage detected