improved
This commit is contained in:
@@ -54,8 +54,6 @@ type StarNotifyS struct {
|
||||
listener net.Listener
|
||||
isUDP bool
|
||||
Sync bool
|
||||
// Stop 停止信 号
|
||||
Stop chan int
|
||||
// UDPConn UDP监听
|
||||
UDPConn *net.UDPConn
|
||||
// Online 当前链接是否处于活跃状态
|
||||
@@ -90,6 +88,9 @@ func (star *StarNotifyS) getName(conn string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func (star *StarNotifyS) Stoped() <-chan struct{} {
|
||||
return star.stopSign.Done()
|
||||
}
|
||||
|
||||
// GetConnPool 获取所有Client端信息
|
||||
func (star *StarNotifyS) GetConnPool() []SMsg {
|
||||
@@ -233,9 +234,8 @@ func (star *StarNotifyS) starinits() {
|
||||
star.FuncLists = make(map[string]func(SMsg) string)
|
||||
star.nickName = make(map[string]string)
|
||||
star.lockPool = make(map[string]SMsg)
|
||||
star.Stop = make(chan int, 5)
|
||||
star.Online = false
|
||||
star.Queue.RestoreDuration(time.Second * 2)
|
||||
star.Queue.RestoreDuration(time.Millisecond * 50)
|
||||
}
|
||||
|
||||
// NewNotifyS 开启一个新的Server端通知
|
||||
@@ -443,10 +443,13 @@ func (star *StarNotifyS) notify() {
|
||||
}
|
||||
data, err := star.Queue.RestoreOne()
|
||||
if err != nil {
|
||||
time.Sleep(time.Microsecond * 2)
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
continue
|
||||
}
|
||||
mode, key, value := star.analyseData(string(data.Msg))
|
||||
if mode == key && mode == value && mode == "" {
|
||||
continue
|
||||
}
|
||||
var rmsg SMsg
|
||||
if !star.isUDP {
|
||||
rmsg = SMsg{data.Conn.(net.Conn), key, value, nil, nil, mode, nil, star.setNickName, star.getName}
|
||||
@@ -507,13 +510,13 @@ func (star *StarNotifyS) notify() {
|
||||
|
||||
func (star *StarNotifyS) analyseData(msg string) (mode, key, value string) {
|
||||
slice := strings.SplitN(msg, "||", 3)
|
||||
if len(slice) < 3 {
|
||||
return "", "", ""
|
||||
}
|
||||
return slice[0], star.trim(slice[1]), slice[2]
|
||||
}
|
||||
|
||||
// ServerStop 用于终止Server端运行
|
||||
func (star *StarNotifyS) ServerStop() {
|
||||
star.cancel()
|
||||
star.Stop <- 1
|
||||
star.Stop <- 1
|
||||
star.Stop <- 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user