bug fix
This commit is contained in:
parent
32bd99788f
commit
6004b3a0f4
19
client.go
19
client.go
@ -24,6 +24,8 @@ type StarNotifyC struct {
|
|||||||
isUDP bool
|
isUDP bool
|
||||||
// Queue 是用来处理收发信息的简单消息队列
|
// Queue 是用来处理收发信息的简单消息队列
|
||||||
Queue *starainrt.StarQueue
|
Queue *starainrt.StarQueue
|
||||||
|
// Online 当前链接是否处于活跃状态
|
||||||
|
Online bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// CMsg 指明当前客户端被通知的关键字
|
// CMsg 指明当前客户端被通知的关键字
|
||||||
@ -38,6 +40,7 @@ func (star *StarNotifyC) starinitc() {
|
|||||||
star.UseChannel = true
|
star.UseChannel = true
|
||||||
star.clientStopSign, star.notifychan, star.Stop = make(chan int, 1), make(chan int, 3), make(chan int, 5)
|
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.clientSign = make(map[string]chan string)
|
||||||
|
star.Online = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify 用于获取一个通知
|
// Notify 用于获取一个通知
|
||||||
@ -77,23 +80,28 @@ func NewNotifyC(netype, value string) (*StarNotifyC, error) {
|
|||||||
for {
|
for {
|
||||||
go func() {
|
go func() {
|
||||||
<-star.clientStopSign
|
<-star.clientStopSign
|
||||||
star.notifychan <- 1
|
star.notifychan <- 2
|
||||||
star.connc.Close()
|
star.connc.Close()
|
||||||
star.Stop <- 1
|
star.Stop <- 0
|
||||||
|
star.Online = false
|
||||||
return
|
return
|
||||||
}()
|
}()
|
||||||
buf := make([]byte, 8192)
|
buf := make([]byte, 8192)
|
||||||
n, err := star.connc.Read(buf)
|
n, err := star.connc.Read(buf)
|
||||||
star.Queue.ParseMessage(buf[0:n], star.connc)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
star.connc.Close()
|
star.connc.Close()
|
||||||
star.Stop <- 1
|
star.Stop <- 1
|
||||||
star.notifychan <- 0
|
star.notifychan <- 3
|
||||||
//star, _ = NewNotifyC(netype, value)
|
//star, _ = NewNotifyC(netype, value)
|
||||||
|
star.Online = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if n != 0 {
|
||||||
|
star.Queue.ParseMessage(buf[0:n], star.connc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
star.Online = true
|
||||||
return &star, nil
|
return &star, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +131,7 @@ func (star *StarNotifyC) cnotify() {
|
|||||||
}
|
}
|
||||||
if data.Msg == "b612ryzstop" {
|
if data.Msg == "b612ryzstop" {
|
||||||
star.clientStopSign <- 0
|
star.clientStopSign <- 0
|
||||||
|
star.Online = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
strs := strings.SplitN(data.Msg, "||", 2)
|
strs := strings.SplitN(data.Msg, "||", 2)
|
||||||
@ -149,7 +158,7 @@ func (star *StarNotifyC) ClientStop() {
|
|||||||
if star.isUDP {
|
if star.isUDP {
|
||||||
star.Send("b612ryzstop")
|
star.Send("b612ryzstop")
|
||||||
}
|
}
|
||||||
star.clientStopSign <- 0
|
star.clientStopSign <- 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNotify 用于设置关键词的调用函数
|
// SetNotify 用于设置关键词的调用函数
|
||||||
|
13
server.go
13
server.go
@ -29,6 +29,8 @@ type StarNotifyS struct {
|
|||||||
isUDP bool
|
isUDP bool
|
||||||
// UDPConn UDP监听
|
// UDPConn UDP监听
|
||||||
UDPConn *net.UDPConn
|
UDPConn *net.UDPConn
|
||||||
|
// Online 当前链接是否处于活跃状态
|
||||||
|
Online bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// SMsg 指明当前服务端被通知的关键字
|
// SMsg 指明当前服务端被通知的关键字
|
||||||
@ -68,6 +70,7 @@ func (star *StarNotifyS) starinits() {
|
|||||||
star.udpPool = make(map[string]*net.UDPAddr)
|
star.udpPool = make(map[string]*net.UDPAddr)
|
||||||
star.FuncLists = make(map[string]func(SMsg) string)
|
star.FuncLists = make(map[string]func(SMsg) string)
|
||||||
star.connPool = make(map[string]net.Conn)
|
star.connPool = make(map[string]net.Conn)
|
||||||
|
star.Online = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNotifyS 开启一个新的Server端通知
|
// NewNotifyS 开启一个新的Server端通知
|
||||||
@ -96,12 +99,13 @@ func doudps(netype, value string) (*StarNotifyS, error) {
|
|||||||
go func() {
|
go func() {
|
||||||
<-star.serverStopSign
|
<-star.serverStopSign
|
||||||
star.notifychan <- 1
|
star.notifychan <- 1
|
||||||
star.notifychan <- 1
|
star.notifychan <- 2
|
||||||
for k, v := range star.udpPool {
|
for k, v := range star.udpPool {
|
||||||
star.UDPConn.WriteToUDP(star.Queue.BuildMessage("b612ryzstop"), v)
|
star.UDPConn.WriteToUDP(star.Queue.BuildMessage("b612ryzstop"), v)
|
||||||
delete(star.connPool, k)
|
delete(star.connPool, k)
|
||||||
}
|
}
|
||||||
star.UDPConn.Close()
|
star.UDPConn.Close()
|
||||||
|
star.Online = false
|
||||||
return
|
return
|
||||||
}()
|
}()
|
||||||
for {
|
for {
|
||||||
@ -117,6 +121,7 @@ func doudps(netype, value string) (*StarNotifyS, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
star.Online = true
|
||||||
return &star, nil
|
return &star, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,13 +138,14 @@ func notudps(netype, value string) (*StarNotifyS, error) {
|
|||||||
for {
|
for {
|
||||||
go func() {
|
go func() {
|
||||||
<-star.serverStopSign
|
<-star.serverStopSign
|
||||||
star.notifychan <- 1
|
star.notifychan <- 3
|
||||||
star.notifychan <- 1
|
star.notifychan <- 4
|
||||||
for k, v := range star.connPool {
|
for k, v := range star.connPool {
|
||||||
v.Close()
|
v.Close()
|
||||||
delete(star.connPool, k)
|
delete(star.connPool, k)
|
||||||
}
|
}
|
||||||
listener.Close()
|
listener.Close()
|
||||||
|
star.Online = false
|
||||||
return
|
return
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -170,6 +176,7 @@ func notudps(netype, value string) (*StarNotifyS, error) {
|
|||||||
star.connPool[conn.RemoteAddr().String()] = conn
|
star.connPool[conn.RemoteAddr().String()] = conn
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
star.Online = true
|
||||||
return &star, nil
|
return &star, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user