Optimize stopping CaptivePortalHandler (#2151)

* Optimize stopping CaptivePortalHandler

* Still use unbuffered channel as we close it instead of sending a signal
This commit is contained in:
lifenjoiner 2022-07-15 03:53:13 +08:00 committed by GitHub
parent 3d641b758a
commit 8e46f44799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 9 deletions

View File

@ -20,8 +20,7 @@ type CaptivePortalHandler struct {
func (captivePortalHandler *CaptivePortalHandler) Stop() { func (captivePortalHandler *CaptivePortalHandler) Stop() {
for _, cancelChannel := range captivePortalHandler.cancelChannels { for _, cancelChannel := range captivePortalHandler.cancelChannels {
cancelChannel <- struct{}{} close(cancelChannel)
<-cancelChannel
} }
} }
@ -84,7 +83,6 @@ func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, i
exit := false exit := false
select { select {
case <-cancelChannel: case <-cancelChannel:
cancelChannel <- struct{}{}
exit = true exit = true
default: default:
} }
@ -96,12 +94,6 @@ func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, i
} }
if err != nil { if err != nil {
dlog.Warn(err) dlog.Warn(err)
select {
case <-cancelChannel:
cancelChannel <- struct{}{}
default:
cancelChannel = make(chan struct{}, 1)
}
return true return true
} }
packet := buffer[:length] packet := buffer[:length]