MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / CheckAndGetAvailableLocalPort

Function CheckAndGetAvailableLocalPort

cli/pkg/common/network.go:108–126  ·  view source on GitHub ↗

检查当前端口是否被占用,并返回一个可用端口

(checkPort int, step int)

Source from the content-addressed store, hash-verified

106
107// 检查当前端口是否被占用,并返回一个可用端口
108func CheckAndGetAvailableLocalPort(checkPort int, step int) (usablePort int, err error) {
109 if step <= 0 {
110 step = 100
111 }
112 usablePort = checkPort
113
114 isPortUnable := false
115 for !isPortUnable {
116 isPortAvailable, err0 := IsPortAvailable(usablePort)
117 err = err0
118 if !isPortAvailable {
119 usablePort += 100
120 } else {
121 isPortUnable = true
122 }
123 }
124
125 return
126}
127
128func isErrorAddressAlreadyInUse(err error) bool {
129 var eOsSyscall *os.SyscallError

Callers

nothing calls this directly

Calls 1

IsPortAvailableFunction · 0.85

Tested by

no test coverage detected