.
git-svn-id: svn://47.119.165.148/zhub@58 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
33
zsub/zgroup.go
Normal file
33
zsub/zgroup.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user