sync support

master
兔子 4 years ago
parent c9cfb6fd8a
commit 79dcaaf249

@ -27,6 +27,7 @@ type StarNotifyC struct {
// UseChannel 是否使用channel作为信息传递
UseChannel bool
isUDP bool
Sync bool
// Queue 是用来处理收发信息的简单消息队列
Queue *starnet.StarQueue
// Online 当前链接是否处于活跃状态
@ -281,10 +282,18 @@ func (star *StarNotifyC) cnotify() {
mode, key, value := strs[0], strs[1], strs[2]
if mode[0:2] != "cr" {
if msg, ok := star.FuncLists[key]; ok {
go msg(CMsg{key, value, mode, nil})
if star.Sync {
msg(CMsg{key, value, mode, nil})
} else {
go msg(CMsg{key, value, mode, nil})
}
} else {
if star.defaultFunc != nil {
go star.defaultFunc(CMsg{key, value, mode, nil})
if star.Sync {
star.defaultFunc(CMsg{key, value, mode, nil})
} else {
go star.defaultFunc(CMsg{key, value, mode, nil})
}
}
}
} else {
@ -296,10 +305,18 @@ func (star *StarNotifyC) cnotify() {
sa.wait <- 1
} else {
if msg, ok := star.FuncLists[key]; ok {
go msg(CMsg{key, value, mode, nil})
if star.Sync {
msg(CMsg{key, value, mode, nil})
} else {
go msg(CMsg{key, value, mode, nil})
}
} else {
if star.defaultFunc != nil {
go star.defaultFunc(CMsg{key, value, mode, nil})
if star.Sync {
star.defaultFunc(CMsg{key, value, mode, nil})
} else {
go star.defaultFunc(CMsg{key, value, mode, nil})
}
}
}
}

@ -49,6 +49,7 @@ type StarNotifyS struct {
udpPool map[string]*net.UDPAddr
listener net.Listener
isUDP bool
Sync bool
// Stop 停止信 号
Stop chan int
// UDPConn UDP监听
@ -432,47 +433,40 @@ func (star *StarNotifyS) notify() {
continue
}
}
if mode[0:2] != "sr" {
go func() {
if msg, ok := star.FuncLists[key]; ok {
sdata := msg(rmsg)
replyFunc := func(key string, rmsg SMsg) {
if msg, ok := star.FuncLists[key]; ok {
sdata := msg(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
} else {
if star.defaultFunc != nil {
sdata := star.defaultFunc(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
} else {
if star.defaultFunc != nil {
sdata := star.defaultFunc(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
}
}
}()
}
}
if mode[0:2] != "sr" {
if star.Sync {
go replyFunc(key, rmsg)
} else {
replyFunc(key, rmsg)
}
} else {
if sa, ok := star.lockPool[mode]; ok {
rmsg.wait = sa.wait
star.lockPool[mode] = rmsg
star.lockPool[mode].wait <- 1
} else {
go func() {
if msg, ok := star.FuncLists[key]; ok {
sdata := msg(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
} else {
if star.defaultFunc != nil {
sdata := star.defaultFunc(rmsg)
if sdata == "" {
return
}
rmsg.Reply(sdata)
}
}
}()
if star.Sync {
go replyFunc(key, rmsg)
} else {
replyFunc(key, rmsg)
}
}
}
}

Loading…
Cancel
Save