增加基础的连接管理与command调度
This commit is contained in:
@ -18,27 +18,46 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
Connection = &connection{table: make([]easymap.EasyMap, 0)}
|
||||
for i := 0; i < 4096; i++ {
|
||||
}
|
||||
c := &connection{}
|
||||
c.table, _ = easymap.NewSegment(4096, true)
|
||||
Connection = c
|
||||
}
|
||||
|
||||
type connection struct {
|
||||
table []easymap.EasyMap
|
||||
table easymap.EasyMap
|
||||
}
|
||||
|
||||
func (c *connection) Store(ctx *context.WSContext) {
|
||||
panic("implement me")
|
||||
c.table.Set(ctx.ConnectionID, ctx)
|
||||
}
|
||||
|
||||
func (c *connection) Del(ctx *context.WSContext) {
|
||||
panic("implement me")
|
||||
c.table.Del(ctx.ConnectionID)
|
||||
}
|
||||
|
||||
func (c *connection) GetCtxList(cidList ...string) []*context.WSContext {
|
||||
panic("implement me")
|
||||
cidTable := make(map[string]bool)
|
||||
for _, item := range cidList {
|
||||
cidTable[item] = true
|
||||
}
|
||||
list := c.table.GetAll()
|
||||
result := make([]*context.WSContext, 0)
|
||||
for _, c := range list {
|
||||
if r, ok := c.(*context.WSContext); ok {
|
||||
if len(cidTable) == 0 {
|
||||
result = append(result, r)
|
||||
continue
|
||||
}
|
||||
if _, exist := cidTable[r.ConnectionID]; exist {
|
||||
result = append(result, r)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *connection) Clear(message string) {
|
||||
panic("implement me")
|
||||
// TODO : 清空连接表
|
||||
// connectionList := c.GetCtxList()
|
||||
}
|
||||
|
Reference in New Issue
Block a user