fix port open fail bug

This commit is contained in:
yicheng 2020-12-06 14:02:45 +08:00
parent 8f9508bd6a
commit f9de9eb409
2 changed files with 16 additions and 5 deletions

View File

@ -155,11 +155,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
DispatchQueue.main.asyncAfter(deadline: .now()+0.2) {
NSApp.reply(toApplicationShouldTerminate: true)
}
DispatchQueue.global().asyncAfter(deadline: .now()+1) {
NSApp.reply(toApplicationShouldTerminate: true)
}
case .timedOut:
Logger.log("ClashX quit after clean up timeout")
DispatchQueue.main.async {
NSApp.reply(toApplicationShouldTerminate: true)
}
DispatchQueue.global().asyncAfter(deadline: .now()+1) {
NSApp.reply(toApplicationShouldTerminate: true)
}
}
}

View File

@ -40,14 +40,19 @@ func checkPortAvailable(port int) bool {
addr := ":"
l, err := net.Listen("tcp", addr+strconv.Itoa(port))
if err != nil {
return false
}
addr = "127.0.0.1:"
l, err = net.Listen("tcp", addr+strconv.Itoa(port))
if err != nil {
log.Warnln("check port fail 0.0.0.0:%d", port)
return false
}
_ = l.Close()
addr = "127.0.0.1:"
l, err = net.Listen("tcp", addr+strconv.Itoa(port))
if err != nil {
log.Warnln("check port fail 127.0.0.1:%d", port)
return false
}
_ = l.Close()
log.Infoln("check port %d success", port)
return true
}