git-svn-id: svn://47.119.165.148/zhub@58 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
lxy
2021-01-08 08:19:58 +00:00
commit c0e9fa0c6b
16 changed files with 1175 additions and 0 deletions

33
zsub/zgroup.go Normal file
View File

@@ -0,0 +1,33 @@
package zsub
import "sync"
type ZGroup struct { //ZGroup
sync.Mutex
conns []*ZConn
offset int
chMsg chan string // 组消息即时投递
}
func createZGroup(c *ZConn) *ZGroup {
zgroup := &ZGroup{
conns: []*ZConn{},
chMsg: make(chan string, 100),
}
// 开启消息推送
go func() {
for {
msg, ok := <-zgroup.chMsg
if !ok {
break
}
for _, c := range zgroup.conns {
(*c.conn).Write([]byte(msg))
zgroup.offset++
}
}
}()
return zgroup
}