Skip to content

Commit aae2daf

Browse files
committed
Change natneg inShutdown to nhttp.AtomicBool
1 parent 50237e9 commit aae2daf

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

natneg/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212
"wwfc/common"
1313
"wwfc/logging"
14+
"wwfc/nhttp"
1415

1516
"github.com/logrusorgru/aurora/v3"
1617
)
@@ -82,7 +83,7 @@ var (
8283
mutex = sync.RWMutex{}
8384
natnegConn net.PacketConn
8485

85-
inShutdown = false
86+
inShutdown nhttp.AtomicBool
8687
waitGroup = sync.WaitGroup{}
8788
)
8889

@@ -97,7 +98,7 @@ func StartServer(reload bool) {
9798
}
9899

99100
natnegConn = conn
100-
inShutdown = false
101+
inShutdown.SetFalse()
101102

102103
if reload {
103104
// Load state
@@ -135,7 +136,7 @@ func StartServer(reload bool) {
135136
logging.Notice("NATNEG", "Listening on", aurora.BrightCyan(address))
136137

137138
for {
138-
if inShutdown {
139+
if inShutdown.IsSet() {
139140
return
140141
}
141142

@@ -153,7 +154,7 @@ func StartServer(reload bool) {
153154
}
154155

155156
func Shutdown() {
156-
inShutdown = true
157+
inShutdown.SetTrue()
157158
natnegConn.Close()
158159
waitGroup.Wait()
159160

@@ -295,7 +296,7 @@ func handleConnection(conn net.PacketConn, addr net.Addr, buffer []byte) {
295296

296297
func closeSession(moduleName string, session *NATNEGSession) {
297298
mutex.Lock()
298-
if inShutdown {
299+
if inShutdown.IsSet() {
299300
mutex.Unlock()
300301
return
301302
}

0 commit comments

Comments
 (0)