fix port open fail bug
This commit is contained in:
parent
8f9508bd6a
commit
f9de9eb409
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user