|
|
|
@ -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 用于设置关键词的调用函数
|
|
|
|
|