outdate
兔子 5 years ago
parent 32bd99788f
commit 6004b3a0f4

@ -24,6 +24,8 @@ type StarNotifyC struct {
isUDP bool
// Queue 是用来处理收发信息的简单消息队列
Queue *starainrt.StarQueue
// Online 当前链接是否处于活跃状态
Online bool
}
// CMsg 指明当前客户端被通知的关键字
@ -38,6 +40,7 @@ func (star *StarNotifyC) starinitc() {
star.UseChannel = true
star.clientStopSign, star.notifychan, star.Stop = make(chan int, 1), make(chan int, 3), make(chan int, 5)
star.clientSign = make(map[string]chan string)
star.Online = false
}
// Notify 用于获取一个通知
@ -77,23 +80,28 @@ func NewNotifyC(netype, value string) (*StarNotifyC, error) {
for {
go func() {
<-star.clientStopSign
star.notifychan <- 1
star.notifychan <- 2
star.connc.Close()
star.Stop <- 1
star.Stop <- 0
star.Online = false
return
}()
buf := make([]byte, 8192)
n, err := star.connc.Read(buf)
star.Queue.ParseMessage(buf[0:n], star.connc)
if err != nil {
star.connc.Close()
star.Stop <- 1
star.notifychan <- 0
star.notifychan <- 3
//star, _ = NewNotifyC(netype, value)
star.Online = false
return
}
if n != 0 {
star.Queue.ParseMessage(buf[0:n], star.connc)
}
}
}()
star.Online = true
return &star, nil
}
@ -123,6 +131,7 @@ func (star *StarNotifyC) cnotify() {
}
if data.Msg == "b612ryzstop" {
star.clientStopSign <- 0
star.Online = false
return
}
strs := strings.SplitN(data.Msg, "||", 2)
@ -149,7 +158,7 @@ func (star *StarNotifyC) ClientStop() {
if star.isUDP {
star.Send("b612ryzstop")
}
star.clientStopSign <- 0
star.clientStopSign <- 1
}
// SetNotify 用于设置关键词的调用函数

@ -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
}

Loading…
Cancel
Save