This commit is contained in:
2019-12-05 16:45:30 +08:00
parent 32bd99788f
commit 6004b3a0f4
2 changed files with 24 additions and 8 deletions
+10 -3
View File
@@ -29,6 +29,8 @@ type StarNotifyS struct {
isUDP bool
// UDPConn UDP监听
UDPConn *net.UDPConn
// Online 当前链接是否处于活跃状态
Online bool
}
// SMsg 指明当前服务端被通知的关键字
@@ -68,6 +70,7 @@ func (star *StarNotifyS) starinits() {
star.udpPool = make(map[string]*net.UDPAddr)
star.FuncLists = make(map[string]func(SMsg) string)
star.connPool = make(map[string]net.Conn)
star.Online = false
}
// NewNotifyS 开启一个新的Server端通知
@@ -96,12 +99,13 @@ func doudps(netype, value string) (*StarNotifyS, error) {
go func() {
<-star.serverStopSign
star.notifychan <- 1
star.notifychan <- 1
star.notifychan <- 2
for k, v := range star.udpPool {
star.UDPConn.WriteToUDP(star.Queue.BuildMessage("b612ryzstop"), v)
delete(star.connPool, k)
}
star.UDPConn.Close()
star.Online = false
return
}()
for {
@@ -117,6 +121,7 @@ func doudps(netype, value string) (*StarNotifyS, error) {
}
}
}()
star.Online = true
return &star, nil
}
@@ -133,13 +138,14 @@ func notudps(netype, value string) (*StarNotifyS, error) {
for {
go func() {
<-star.serverStopSign
star.notifychan <- 1
star.notifychan <- 1
star.notifychan <- 3
star.notifychan <- 4
for k, v := range star.connPool {
v.Close()
delete(star.connPool, k)
}
listener.Close()
star.Online = false
return
}()
@@ -170,6 +176,7 @@ func notudps(netype, value string) (*StarNotifyS, error) {
star.connPool[conn.RemoteAddr().String()] = conn
}
}()
star.Online = true
return &star, nil
}